diff --git "a/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_BigOperators_Ring.jsonl" "b/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_BigOperators_Ring.jsonl" new file mode 100644--- /dev/null +++ "b/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_BigOperators_Ring.jsonl" @@ -0,0 +1,124 @@ +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝ : CommMonoid β\nx : β\nf : α → ℕ\n⊢ ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n ","nextTactic":"apply Finset.induction","declUpToTactic":"theorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.37_0.3KYKAiUqy9KHW5V","decl":"theorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x "} +{"state":"case empty\nα : Type u\nβ : Type v\nγ : Type w\ns s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝ : CommMonoid β\nx : β\nf : α → ℕ\n⊢ ∏ i in ∅, x ^ f i = x ^ ∑ x in ∅, f x","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · ","nextTactic":"simp","declUpToTactic":"theorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.37_0.3KYKAiUqy9KHW5V","decl":"theorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝ : CommMonoid β\nx : β\nf : α → ℕ\n⊢ ∀ ⦃a : α⦄ {s : Finset α},\n a ∉ s → ∏ i in s, x ^ f i = x ^ ∑ x in s, f x → ∏ i in insert a s, x ^ f i = x ^ ∑ x in insert a s, f x","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · ","nextTactic":"intro a s has H","declUpToTactic":"theorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.37_0.3KYKAiUqy9KHW5V","decl":"theorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g : α → β\ninst✝ : CommMonoid β\nx : β\nf : α → ℕ\na : α\ns : Finset α\nhas : a ∉ s\nH : ∏ i in s, x ^ f i = x ^ ∑ x in s, f x\n⊢ ∏ i in insert a s, x ^ f i = x ^ ∑ x in insert a s, f x","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n ","nextTactic":"rw [Finset.prod_insert has]","declUpToTactic":"theorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.37_0.3KYKAiUqy9KHW5V","decl":"theorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g : α → β\ninst✝ : CommMonoid β\nx : β\nf : α → ℕ\na : α\ns : Finset α\nhas : a ∉ s\nH : ∏ i in s, x ^ f i = x ^ ∑ x in s, f x\n⊢ x ^ f a * ∏ x_1 in s, x ^ f x_1 = x ^ ∑ x in insert a s, f x","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n ","nextTactic":"rw [Finset.sum_insert has]","declUpToTactic":"theorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.37_0.3KYKAiUqy9KHW5V","decl":"theorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g : α → β\ninst✝ : CommMonoid β\nx : β\nf : α → ℕ\na : α\ns : Finset α\nhas : a ∉ s\nH : ∏ i in s, x ^ f i = x ^ ∑ x in s, f x\n⊢ x ^ f a * ∏ x_1 in s, x ^ f x_1 = x ^ (f a + ∑ x in s, f x)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n ","nextTactic":"rw [pow_add]","declUpToTactic":"theorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.37_0.3KYKAiUqy9KHW5V","decl":"theorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g : α → β\ninst✝ : CommMonoid β\nx : β\nf : α → ℕ\na : α\ns : Finset α\nhas : a ∉ s\nH : ∏ i in s, x ^ f i = x ^ ∑ x in s, f x\n⊢ x ^ f a * ∏ x_1 in s, x ^ f x_1 = x ^ f a * x ^ ∑ x in s, f x","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n ","nextTactic":"rw [H]","declUpToTactic":"theorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.37_0.3KYKAiUqy9KHW5V","decl":"theorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns s₁✝ s₂✝ : Finset α\na : α\nb : β\nf g : α → β\ninst✝ : NonUnitalNonAssocSemiring β\nι₁ : Type u_1\nι₂ : Type u_2\ns₁ : Finset ι₁\ns₂ : Finset ι₂\nf₁ : ι₁ → β\nf₂ : ι₂ → β\n⊢ (∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂ = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n ","nextTactic":"rw [sum_product]","declUpToTactic":"theorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.62_0.3KYKAiUqy9KHW5V","decl":"theorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns s₁✝ s₂✝ : Finset α\na : α\nb : β\nf g : α → β\ninst✝ : NonUnitalNonAssocSemiring β\nι₁ : Type u_1\nι₂ : Type u_2\ns₁ : Finset ι₁\ns₂ : Finset ι₂\nf₁ : ι₁ → β\nf₂ : ι₂ → β\n⊢ (∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂ = ∑ x in s₁, ∑ y in s₂, f₁ (x, y).1 * f₂ (x, y).2","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n ","nextTactic":"rw [sum_mul]","declUpToTactic":"theorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.62_0.3KYKAiUqy9KHW5V","decl":"theorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns s₁✝ s₂✝ : Finset α\na : α\nb : β\nf g : α → β\ninst✝ : NonUnitalNonAssocSemiring β\nι₁ : Type u_1\nι₂ : Type u_2\ns₁ : Finset ι₁\ns₂ : Finset ι₂\nf₁ : ι₁ → β\nf₂ : ι₂ → β\n⊢ ∑ x in s₁, f₁ x * ∑ x₂ in s₂, f₂ x₂ = ∑ x in s₁, ∑ y in s₂, f₁ (x, y).1 * f₂ (x, y).2","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n ","nextTactic":"rw [sum_congr rfl]","declUpToTactic":"theorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.62_0.3KYKAiUqy9KHW5V","decl":"theorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns s₁✝ s₂✝ : Finset α\na : α\nb : β\nf g : α → β\ninst✝ : NonUnitalNonAssocSemiring β\nι₁ : Type u_1\nι₂ : Type u_2\ns₁ : Finset ι₁\ns₂ : Finset ι₂\nf₁ : ι₁ → β\nf₂ : ι₂ → β\n⊢ ∀ x ∈ s₁, f₁ x * ∑ x₂ in s₂, f₂ x₂ = ∑ y in s₂, f₁ (x, y).1 * f₂ (x, y).2","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n ","nextTactic":"intros","declUpToTactic":"theorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.62_0.3KYKAiUqy9KHW5V","decl":"theorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns s₁✝ s₂✝ : Finset α\na : α\nb : β\nf g : α → β\ninst✝ : NonUnitalNonAssocSemiring β\nι₁ : Type u_1\nι₂ : Type u_2\ns₁ : Finset ι₁\ns₂ : Finset ι₂\nf₁ : ι₁ → β\nf₂ : ι₂ → β\nx✝ : ι₁\na✝ : x✝ ∈ s₁\n⊢ f₁ x✝ * ∑ x₂ in s₂, f₂ x₂ = ∑ y in s₂, f₁ (x✝, y).1 * f₂ (x✝, y).2","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n ","nextTactic":"rw [mul_sum]","declUpToTactic":"theorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.62_0.3KYKAiUqy9KHW5V","decl":"theorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb✝ : β\nf✝ g : α → β\ninst✝ : NonUnitalSemiring β\nb : β\ns : Finset α\nf : α → β\nh : ∀ x ∈ s, b ∣ f x\ny : β\nhy : y ∈ Multiset.map (fun x => f x) s.val\n⊢ b ∣ y","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by ","nextTactic":"rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩","declUpToTactic":"theorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.76_0.3KYKAiUqy9KHW5V","decl":"theorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x "} +{"state":"case intro.intro\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb✝ : β\nf✝ g : α → β\ninst✝ : NonUnitalSemiring β\nb : β\ns : Finset α\nf : α → β\nh : ∀ x ∈ s, b ∣ f x\nx : α\nhx : x ∈ s.val\nhy : f x ∈ Multiset.map (fun x => f x) s.val\n⊢ b ∣ f x","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; ","nextTactic":"exact h x hx","declUpToTactic":"theorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.76_0.3KYKAiUqy9KHW5V","decl":"theorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g : α → β\ninst✝¹ : NonAssocSemiring β\ninst✝ : DecidableEq α\ns : Finset α\nf : α → β\na : α\n⊢ (∑ x in s, f x * if a = x then 1 else 0) = if a ∈ s then f a else 0","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by ","nextTactic":"simp","declUpToTactic":"theorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.83_0.3KYKAiUqy9KHW5V","decl":"theorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g : α → β\ninst✝¹ : NonAssocSemiring β\ninst✝ : DecidableEq α\ns : Finset α\nf : α → β\na : α\n⊢ ∑ x in s, (if a = x then 1 else 0) * f x = if a ∈ s then f a else 0","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by ","nextTactic":"simp","declUpToTactic":"theorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.87_0.3KYKAiUqy9KHW5V","decl":"theorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb✝ : β\nf✝ g : α → β\ninst✝ : DivisionSemiring β\ns : Finset α\nf : α → β\nb : β\n⊢ (∑ x in s, f x) / b = ∑ x in s, f x / b","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by ","nextTactic":"simp only [div_eq_mul_inv, sum_mul]","declUpToTactic":"theorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.93_0.3KYKAiUqy9KHW5V","decl":"theorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\ns : Finset α\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\n⊢ ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n ","nextTactic":"induction' s using Finset.induction with a s ha ih","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case empty\nα : Type u\nβ : Type v\nγ : Type w\ns s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\n⊢ ∏ a in ∅, ∑ b in t a, f a b = ∑ p in pi ∅ t, ∏ x in attach ∅, f (↑x) (p ↑x (_ : ↑x ∈ ∅))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · ","nextTactic":"rw [pi_empty, sum_singleton]","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case empty\nα : Type u\nβ : Type v\nγ : Type w\ns s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\n⊢ ∏ a in ∅, ∑ b in t a, f a b = ∏ x in attach ∅, f (↑x) (Pi.empty (fun a => δ a) ↑x (_ : ↑x ∈ ∅))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n ","nextTactic":"rfl","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\n⊢ ∏ a in insert a s, ∑ b in t a, f a b =\n ∑ p in pi (insert a s) t, ∏ x in attach (insert a s), f (↑x) (p ↑x (_ : ↑x ∈ insert a s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · ","nextTactic":"have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\n⊢ ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n ","nextTactic":"intro x _ y _ h","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ��� y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝² : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nx : δ a\na✝¹ : x ∈ t a\ny : δ a\na✝ : y ∈ t a\nh : x ≠ y\n⊢ Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n ","nextTactic":"simp only [disjoint_iff_ne, mem_image]","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝² : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nx : δ a\na✝¹ : x ∈ t a\ny : δ a\na✝ : y ∈ t a\nh : x ≠ y\n⊢ ∀ (a_1 : (a' : α) → a' ∈ insert a s → δ a'),\n (∃ a_2 ∈ pi s t, Pi.cons s a x a_2 = a_1) →\n ∀ (b : (a' : α) → a' ∈ insert a s → δ a'), (∃ a_3 ∈ pi s t, Pi.cons s a y a_3 = b) → a_1 ≠ b","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n ","nextTactic":"rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case intro.intro.intro.intro\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝³ : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nx : δ a\na✝² : x ∈ t a\ny : δ a\na✝¹ : y ∈ t a\nh : x ≠ y\na✝ : (a' : α) → a' ∈ insert a s → δ a'\np₂ : (a : α) → a ∈ s → δ a\nleft✝¹ : p₂ ∈ pi s t\neq₂ : Pi.cons s a x p₂ = a✝\nb✝ : (a' : α) → a' ∈ insert a s → δ a'\np₃ : (a : α) → a ∈ s → δ a\nleft✝ : p₃ ∈ pi s t\neq₃ : Pi.cons s a y p₃ = b✝\neq : a✝ = b✝\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n ","nextTactic":"have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝³ : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nx : δ a\na✝² : x ∈ t a\ny : δ a\na✝¹ : y ∈ t a\nh : x ≠ y\na✝ : (a' : α) → a' ∈ insert a s → δ a'\np₂ : (a : α) → a ∈ s → δ a\nleft✝¹ : p₂ ∈ pi s t\neq₂ : Pi.cons s a x p₂ = a✝\nb✝ : (a' : α) → a' ∈ insert a s → δ a'\np₃ : (a : α) → a ∈ s → δ a\nleft✝ : p₃ ∈ pi s t\neq₃ : Pi.cons s a y p₃ = b✝\neq : a✝ = b✝\n⊢ Pi.cons s a x p₂ a (_ : a ∈ insert a s) = Pi.cons s a y p₃ a (_ : a ∈ insert a s)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by ","nextTactic":"rw [eq₂, eq₃, eq]","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case intro.intro.intro.intro\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝³ : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nx : δ a\na✝² : x ∈ t a\ny : δ a\na✝¹ : y ∈ t a\nh : x ≠ y\na✝ : (a' : α) → a' ∈ insert a s → δ a'\np₂ : (a : α) → a ∈ s → δ a\nleft✝¹ : p₂ ∈ pi s t\neq₂ : Pi.cons s a x p₂ = a✝\nb✝ : (a' : α) → a' ∈ insert a s → δ a'\np₃ : (a : α) → a ∈ s → δ a\nleft✝ : p₃ ∈ pi s t\neq₃ : Pi.cons s a y p₃ = b✝\neq : a✝ = b✝\nthis : Pi.cons s a x p₂ a (_ : a ∈ insert a s) = Pi.cons s a y p₃ a (_ : a ∈ insert a s)\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n ","nextTactic":"rw [Pi.cons_same] at this","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case intro.intro.intro.intro\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝³ : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nx : δ a\na✝² : x ∈ t a\ny : δ a\na✝¹ : y ∈ t a\nh : x ≠ y\na✝ : (a' : α) → a' ∈ insert a s → δ a'\np₂ : (a : α) → a ∈ s → δ a\nleft✝¹ : p₂ ∈ pi s t\neq₂ : Pi.cons s a x p₂ = a✝\nb✝ : (a' : α) → a' ∈ insert a s → δ a'\np₃ : (a : α) → a ∈ s → δ a\nleft✝ : p₃ ∈ pi s t\neq₃ : Pi.cons s a y p₃ = b✝\neq : a✝ = b✝\nthis : x = Pi.cons s a y p₃ a (_ : a ∈ insert a s)\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n ","nextTactic":"rw [Pi.cons_same] at this","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case intro.intro.intro.intro\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝³ : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nx : δ a\na✝² : x ∈ t a\ny : δ a\na✝¹ : y ∈ t a\nh : x ≠ y\na✝ : (a' : α) → a' ∈ insert a s → δ a'\np₂ : (a : α) → a ∈ s → δ a\nleft✝¹ : p₂ ∈ pi s t\neq₂ : Pi.cons s a x p₂ = a✝\nb✝ : (a' : α) → a' ∈ insert a s → δ a'\np₃ : (a : α) → a ∈ s → δ a\nleft✝ : p₃ ∈ pi s t\neq₃ : Pi.cons s a y p₃ = b✝\neq : a✝ = b✝\nthis : x = y\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n ","nextTactic":"exact h this","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\n⊢ ∏ a in insert a s, ∑ b in t a, f a b =\n ∑ p in pi (insert a s) t, ∏ x in attach (insert a s), f (↑x) (p ↑x (_ : ↑x ∈ insert a s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n ","nextTactic":"rw [prod_insert ha]","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\n⊢ (∑ b in t a, f a b) * ∏ x in s, ∑ b in t x, f x b =\n ∑ p in pi (insert a s) t, ∏ x in attach (insert a s), f (↑x) (p ↑x (_ : ↑x ∈ insert a s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n ","nextTactic":"rw [pi_insert ha]","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\n⊢ (∑ b in t a, f a b) * ∏ x in s, ∑ b in t x, f x b =\n ∑ p in Finset.biUnion (t a) fun b => image (Pi.cons s a b) (pi s t),\n ∏ x in attach (insert a s), f (↑x) (p ↑x (_ : ↑x ∈ insert a s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n ","nextTactic":"rw [ih]","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\n⊢ (∑ b in t a, f a b) * ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s)) =\n ∑ p in Finset.biUnion (t a) fun b => image (Pi.cons s a b) (pi s t),\n ∏ x in attach (insert a s), f (↑x) (p ↑x (_ : ↑x ∈ insert a s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n ","nextTactic":"rw [sum_mul]","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\n⊢ ∑ x in t a, f a x * ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s)) =\n ∑ p in Finset.biUnion (t a) fun b => image (Pi.cons s a b) (pi s t),\n ∏ x in attach (insert a s), f (↑x) (p ↑x (_ : ↑x ∈ insert a s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n ","nextTactic":"rw [sum_biUnion h₁]","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\n⊢ ∑ x in t a, f a x * ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s)) =\n ∑ x in t a, ∑ i in image (Pi.cons s a x) (pi s t), ∏ x in attach (insert a s), f (↑x) (i ↑x (_ : ↑x ∈ insert a s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n ","nextTactic":"refine' sum_congr rfl fun b _ => _","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb✝ : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\nb : δ a\nx✝ : b ∈ t a\n⊢ f a b * ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s)) =\n ∑ i in image (Pi.cons s a b) (pi s t), ∏ x in attach (insert a s), f (↑x) (i ↑x (_ : ↑x ∈ insert a s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n ","nextTactic":"have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb✝ : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\nb : δ a\nx✝ : b ∈ t a\nh₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂\n⊢ f a b * ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s)) =\n ∑ i in image (Pi.cons s a b) (pi s t), ∏ x in attach (insert a s), f (↑x) (i ↑x (_ : ↑x ∈ insert a s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n ","nextTactic":"rw [sum_image h₂]","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb✝ : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\nb : δ a\nx✝ : b ∈ t a\nh₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂\n⊢ f a b * ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s)) =\n ∑ x in pi s t, ∏ x_1 in attach (insert a s), f (↑x_1) (Pi.cons s a b x ↑x_1 (_ : ↑x_1 ∈ insert a s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n ","nextTactic":"rw [mul_sum]","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb✝ : β\nf✝ g : �� → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\nb : δ a\nx✝ : b ∈ t a\nh₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂\n⊢ ∑ x in pi s t, f a b * ∏ x_1 in attach s, f (↑x_1) (x ↑x_1 (_ : ↑x_1 ∈ s)) =\n ∑ x in pi s t, ∏ x_1 in attach (insert a s), f (↑x_1) (Pi.cons s a b x ↑x_1 (_ : ↑x_1 ∈ insert a s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n ","nextTactic":"refine' sum_congr rfl fun g _ => _","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb✝ : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\nb : δ a\nx✝¹ : b ∈ t a\nh₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂\ng : (a : α) → a ∈ s → δ a\nx✝ : g ∈ pi s t\n⊢ f a b * ∏ x in attach s, f (↑x) (g ↑x (_ : ↑x ∈ s)) =\n ∏ x in attach (insert a s), f (↑x) (Pi.cons s a b g ↑x (_ : ↑x ∈ insert a s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n ","nextTactic":"rw [attach_insert]","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb✝ : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\nb : δ a\nx✝¹ : b ∈ t a\nh₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂\ng : (a : α) → a ∈ s → δ a\nx✝ : g ∈ pi s t\n⊢ f a b * ∏ x in attach s, f (↑x) (g ↑x (_ : ↑x ∈ s)) =\n ∏ x in\n insert { val := a, property := (_ : a ∈ insert a s) }\n (image (fun x => { val := ↑x, property := (_ : ↑x ∈ insert a s) }) (attach s)),\n f (↑x) (Pi.cons s a b g ↑x (_ : ↑x ∈ insert a s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n ","nextTactic":"rw [prod_insert]","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb✝ : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\nb : δ a\nx✝¹ : b ∈ t a\nh₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂\ng : (a : α) → a ∈ s → δ a\nx✝ : g ∈ pi s t\n⊢ f a b * ∏ x in attach s, f (↑x) (g ↑x (_ : ↑x ∈ s)) =\n f (↑{ val := a, property := (_ : a ∈ insert a s) })\n (Pi.cons s a b g ↑{ val := a, property := (_ : a ∈ insert a s) }\n (_ : ↑{ val := a, property := (_ : a ∈ insert a s) } ∈ insert a s)) *\n ∏ x in image (fun x => { val := ↑x, property := (_ : ↑x ∈ insert a s) }) (attach s),\n f (↑x) (Pi.cons s a b g ↑x (_ : ↑x ∈ insert a s))\ncase insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb✝ : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\nb : δ a\nx✝¹ : b ∈ t a\nh₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂\ng : (a : α) → a ∈ s → δ a\nx✝ : g ∈ pi s t\n⊢ { val := a, property := (_ : a ∈ insert a s) } ∉\n image (fun x => { val := ↑x, property := (_ : ↑x ∈ insert a s) }) (attach s)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n ","nextTactic":"rw [prod_image]","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb✝ : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\nb : δ a\nx✝¹ : b ∈ t a\nh₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂\ng : (a : α) → a ∈ s → δ a\nx✝ : g ∈ pi s t\n⊢ f a b * ∏ x in attach s, f (↑x) (g ↑x (_ : ↑x ∈ s)) =\n f (↑{ val := a, property := (_ : a ∈ insert a s) })\n (Pi.cons s a b g ↑{ val := a, property := (_ : a ∈ insert a s) }\n (_ : ↑{ val := a, property := (_ : a ∈ insert a s) } ∈ insert a s)) *\n ∏ x in attach s,\n f (↑{ val := ↑x, property := (_ : ↑x ∈ insert a s) })\n (Pi.cons s a b g ↑{ val := ↑x, property := (_ : ↑x ∈ insert a s) }\n (_ : ↑{ val := ↑x, property := (_ : ↑x ∈ insert a s) } ∈ insert a s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · ","nextTactic":"simp only [Pi.cons_same]","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb✝ : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\nb : δ a\nx✝¹ : b ∈ t a\nh₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂\ng : (a : α) → a ∈ s → δ a\nx✝ : g ∈ pi s t\n⊢ f a b * ∏ x in attach s, f (↑x) (g ↑x (_ : ↑x ∈ s)) =\n f a b *\n ∏ x in attach s,\n f (↑x)\n (Pi.cons s a b g ↑{ val := ↑x, property := (_ : ↑x ∈ insert a s) }\n (_ : ↑{ val := ↑x, property := (_ : ↑x ∈ insert a s) } ∈ insert a s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n ","nextTactic":"congr with ⟨v, hv⟩","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert.e_a.e_f.h.mk\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb✝ : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\nb : δ a\nx✝¹ : b ∈ t a\nh₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂\ng : (a : α) → a ∈ s → δ a\nx✝ : g ∈ pi s t\nv : α\nhv : v ∈ s\n⊢ f (↑{ val := v, property := hv }) (g ↑{ val := v, property := hv } (_ : ↑{ val := v, property := hv } ∈ s)) =\n f (↑{ val := v, property := hv })\n (Pi.cons s a b g\n ↑{ val := ↑{ val := v, property := hv }, property := (_ : ↑{ val := v, property := hv } ∈ insert a s) }\n (_ :\n ↑{ val := ↑{ val := v, property := hv }, property := (_ : ↑{ val := v, property := hv } ∈ insert a s) } ∈\n insert a s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n ","nextTactic":"congr","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert.e_a.e_f.h.mk.e_a\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb✝ : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\nb : δ a\nx✝¹ : b ∈ t a\nh₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂\ng : (a : α) → a ∈ s → δ a\nx✝ : g ∈ pi s t\nv : α\nhv : v ∈ s\n⊢ g ↑{ val := v, property := hv } (_ : ↑{ val := v, property := hv } ∈ s) =\n Pi.cons s a b g\n ↑{ val := ↑{ val := v, property := hv }, property := (_ : ↑{ val := v, property := hv } ∈ insert a s) }\n (_ :\n ↑{ val := ↑{ val := v, property := hv }, property := (_ : ↑{ val := v, property := hv } ∈ insert a s) } ∈\n insert a s)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n ","nextTactic":"exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb✝ : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\nb : δ a\nx✝¹ : b ∈ t a\nh₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂\ng : (a : α) → a ∈ s → δ a\nx✝ : g ∈ pi s t\nv : α\nhv : v ∈ s\n⊢ a ≠ ↑{ val := v, property := hv }","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by ","nextTactic":"rintro rfl","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s�� s₂ : Finset α\na✝ : α\nb✝ : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\nb : δ a\nx✝¹ : b ∈ t a\nh₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂\ng : (a : α) → a ∈ s → δ a\nx✝ : g ∈ pi s t\nhv : a ∈ s\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; ","nextTactic":"exact ha hv","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb✝ : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\nb : δ a\nx✝¹ : b ∈ t a\nh₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂\ng : (a : α) → a ∈ s → δ a\nx✝ : g ∈ pi s t\n⊢ ∀ x ∈ attach s,\n ∀ y ∈ attach s,\n { val := ↑x, property := (_ : ↑x ∈ insert a s) } = { val := ↑y, property := (_ : ↑y ∈ insert a s) } → x = y","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · ","nextTactic":"exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"case insert\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb✝ : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nδ : α → Type u_1\ninst✝¹ : DecidableEq α\ninst✝ : (a : α) → DecidableEq (δ a)\nt : (a : α) → Finset (δ a)\nf : (a : α) → δ a → β\na : α\ns : Finset α\nha : a ∉ s\nih : ∏ a in s, ∑ b in t a, f a b = ∑ p in pi s t, ∏ x in attach s, f (↑x) (p ↑x (_ : ↑x ∈ s))\nh₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y → Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t))\nb : δ a\nx✝¹ : b ∈ t a\nh₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂\ng : (a : α) → a ∈ s → δ a\nx✝ : g ∈ pi s t\n⊢ { val := a, property := (_ : a ∈ insert a s) } ∉\n image (fun x => { val := ↑x, property := (_ : ↑x ∈ insert a s) }) (attach s)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · ","nextTactic":"simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha","declUpToTactic":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.101_0.3KYKAiUqy9KHW5V","decl":"/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\n⊢ ∏ a in s, (f a + g a) = ∑ t in powerset s, (∏ a in t, f a) * ∏ a in s \\ t, g a","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n ","nextTactic":"classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\n⊢ ∏ a in s, (f a + g a) = ∑ t in powerset s, (∏ a in t, f a) * ∏ a in s \\ t, g a","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n ","nextTactic":"calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\n⊢ ∏ a in s, (f a + g a) = ∏ a in s, ∑ p in {True, False}, if p then f a else g a","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring ��]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by ","nextTactic":"simp","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\n⊢ ∀ (a : (a : α) → a ∈ s → Prop) (ha : a ∈ pi s fun x => {True, False}),\n (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a ha ∈ powerset s","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by ","nextTactic":"simp","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na : (a : α) → a ∈ s → Prop\nx✝ : a ∈ pi s fun x => {True, False}\n⊢ (∏ a_1 in attach s, if a ↑a_1 (_ : ↑a_1 ∈ s) then f ↑a_1 else g ↑a_1) =\n (∏ a in (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a x✝, f a) *\n ∏ a in s \\ (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a x✝, g a","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n ","nextTactic":"rw [prod_ite]","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na : (a : α) → a ∈ s → Prop\nx✝ : a ∈ pi s fun x => {True, False}\n⊢ (∏ x in filter (fun a_1 => a ↑a_1 (_ : ↑a_1 ∈ s)) (attach s), f ↑x) *\n ∏ x in filter (fun x => ¬a ↑x (_ : ↑x ∈ s)) (attach s), g ↑x =\n (∏ a in (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a x✝, f a) *\n ∏ a in s \\ (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a x✝, g a","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n ","nextTactic":"congr 1","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"case e_a\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na : (a : α) → a ∈ s → Prop\nx✝ : a ∈ pi s fun x => {True, False}\n⊢ ∏ x in filter (fun a_1 => a ↑a_1 (_ : ↑a_1 ∈ s)) (attach s), f ↑x =\n ∏ a in (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a x✝, f a\ncase e_a\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na : (a : α) → a ∈ s → Prop\nx✝ : a ∈ pi s fun x => {True, False}\n⊢ ∏ x in filter (fun x => ¬a ↑x (_ : ↑x ∈ s)) (attach s), g ↑x =\n ∏ a in s \\ (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a x✝, g a","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n ","nextTactic":"exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na : (a : α) → a ∈ s → Prop\nx✝ : a ∈ pi s fun x => {True, False}\n⊢ ∀ (a_1 : { x // x ∈ s }) (ha : a_1 ∈ filter (fun a_2 => a ↑a_2 (_ : ↑a_2 ∈ s)) (attach s)),\n (fun a_2 x => ↑a_2) a_1 ha ∈ (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a x✝","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by ","nextTactic":"simp","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na : (a : α) → a ∈ s → Prop\nx✝ : a ∈ pi s fun x => {True, False}\n⊢ ∀ (a_1 : { x // x ∈ s }) (ha : a_1 ∈ filter (fun a_2 => a ↑a_2 (_ : ↑a_2 ∈ s)) (attach s)),\n f ↑a_1 = f ((fun a_2 x => ↑a_2) a_1 ha)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid ��]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by ","nextTactic":"simp","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝¹ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na✝ : (a : α) → a ∈ s → Prop\nx✝ : a✝ ∈ pi s fun x => {True, False}\na : α\nha : a ∈ (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a✝ x✝\n⊢ (fun a ha => { val := a, property := (_ : a ∈ s) }) a ha ∈ filter (fun a => a✝ ↑a (_ : ↑a ∈ s)) (attach s)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by ","nextTactic":"simp at ha","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝¹ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na✝ : (a : α) → a ∈ s → Prop\nx✝ : a✝ ∈ pi s fun x => {True, False}\na : α\nha✝ : a ∈ (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a✝ x✝\nha : a ∈ s ∧ ∀ (h : a ∈ s), a✝ a h\n⊢ (fun a ha => { val := a, property := (_ : a ∈ s) }) a ha✝ ∈ filter (fun a => a✝ ↑a (_ : ↑a ∈ s)) (attach s)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; ","nextTactic":"simp","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝¹ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na✝ : (a : α) → a ∈ s → Prop\nx✝ : a✝ ∈ pi s fun x => {True, False}\na : α\nha✝ : a ∈ (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a✝ x✝\nha : a ∈ s ∧ ∀ (h : a ∈ s), a✝ a h\n⊢ a✝ a (_ : ↑{ val := a, property := (_ : a ∈ s) } ∈ s)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; ","nextTactic":"tauto","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na : (a : α) → a ∈ s → Prop\nx✝ : a ∈ pi s fun x => {True, False}\n⊢ ∀ (a_1 : { x // x ∈ s }) (ha : a_1 ∈ filter (fun a_2 => a ↑a_2 (_ : ↑a_2 ∈ s)) (attach s)),\n (fun a_2 ha => { val := a_2, property := (_ : a_2 ∈ s) }) ((fun a_2 x => ↑a_2) a_1 ha)\n (_ : (fun a_2 x => ↑a_2) a_1 ha ∈ (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a x✝) =\n a_1","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by ","nextTactic":"simp","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na : (a : α) → a ∈ s → Prop\nx✝ : a ∈ pi s fun x => {True, False}\n⊢ ∀ (a_1 : α) (ha : a_1 ∈ (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a x✝),\n (fun a_2 x => ↑a_2) ((fun a_2 ha => { val := a_2, property := (_ : a_2 ∈ s) }) a_1 ha)\n (_ :\n (fun a_2 ha => { val := a_2, property := (_ : a_2 ∈ s) }) a_1 ha ∈\n filter (fun a_2 => a ↑a_2 (_ : ↑a_2 ∈ s)) (attach s)) =\n a_1","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by ","nextTactic":"simp","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"case e_a\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na : (a : α) → a ∈ s → Prop\nx✝ : a ∈ pi s fun x => {True, False}\n⊢ ∏ x in filter (fun x => ¬a ↑x (_ : ↑x ∈ s)) (attach s), g ↑x =\n ∏ a in s \\ (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a x✝, g a","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n ","nextTactic":"exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na : (a : α) → a ∈ s → Prop\nx✝ : a ∈ pi s fun x => {True, False}\n⊢ ∀ (a_1 : { x // x ∈ s }) (ha : a_1 ∈ filter (fun x => ¬a ↑x (_ : ↑x ∈ s)) (attach s)),\n (fun a_2 x => ↑a_2) a_1 ha ∈ s \\ (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a x✝","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by ","nextTactic":"simp","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na : (a : α) → a ∈ s → Prop\nx✝ : a ∈ pi s fun x => {True, False}\n⊢ ∀ (a_1 : { x // x ∈ s }) (ha : a_1 ∈ filter (fun x => ¬a ↑x (_ : ↑x ∈ s)) (attach s)),\n g ↑a_1 = g ((fun a_2 x => ↑a_2) a_1 ha)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by ","nextTactic":"simp","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝¹ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na✝ : (a : α) → a ∈ s → Prop\nx✝ : a✝ ∈ pi s fun x => {True, False}\na : α\nha : a ∈ s \\ (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a✝ x✝\n⊢ (fun a ha => { val := a, property := (_ : a ∈ s) }) a ha ∈ filter (fun x => ¬a✝ ↑x (_ : ↑x ∈ s)) (attach s)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by ","nextTactic":"simp at ha","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝¹ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na✝ : (a : α) → a ∈ s → Prop\nx✝ : a✝ ∈ pi s fun x => {True, False}\na : α\nha✝ : a ∈ s \\ (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a✝ x✝\nha : a ∈ s ∧ (a ∈ s → ∃ (x : a ∈ s), ¬a✝ a x)\n⊢ (fun a ha => { val := a, property := (_ : a ∈ s) }) a ha✝ ∈ filter (fun x => ¬a✝ ↑x (_ : ↑x ∈ s)) (attach s)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; ","nextTactic":"simp","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝¹ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na✝ : (a : α) → a ∈ s → Prop\nx✝ : a✝ ∈ pi s fun x => {True, False}\na : α\nha✝ : a ∈ s \\ (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a✝ x✝\nha : a ∈ s ∧ (a ∈ s → ∃ (x : a ∈ s), ¬a✝ a x)\n⊢ ¬a✝ a (_ : ↑{ val := a, property := (_ : a ∈ s) } ∈ s)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f��� x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; ","nextTactic":"tauto","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na : (a : α) → a ∈ s → Prop\nx✝ : a ∈ pi s fun x => {True, False}\n⊢ ∀ (a_1 : { x // x ∈ s }) (ha : a_1 ∈ filter (fun x => ¬a ↑x (_ : ↑x ∈ s)) (attach s)),\n (fun a_2 ha => { val := a_2, property := (_ : a_2 ∈ s) }) ((fun a_2 x => ↑a_2) a_1 ha)\n (_ : (fun a_2 x => ↑a_2) a_1 ha ∈ s \\ (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a x✝) =\n a_1","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ��� a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by ","nextTactic":"simp","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\na : (a : α) → a ∈ s → Prop\nx✝ : a ∈ pi s fun x => {True, False}\n⊢ ∀ (a_1 : α) (ha : a_1 ∈ s \\ (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a x✝),\n (fun a_2 x => ↑a_2) ((fun a_2 ha => { val := a_2, property := (_ : a_2 ∈ s) }) a_1 ha)\n (_ :\n (fun a_2 ha => { val := a_2, property := (_ : a_2 ∈ s) }) a_1 ha ∈\n filter (fun x => ¬a ↑x (_ : ↑x ∈ s)) (attach s)) =\n a_1","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by ","nextTactic":"simp","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\n⊢ ∀ (a : Finset α) (ha : a ∈ powerset s), (fun t x a x => a ∈ t) a ha ∈ pi s fun x => {True, False}","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by ","nextTactic":"simp [Classical.em]","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ��� a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\n⊢ ∀ (a : (a : α) → a ∈ s → Prop) (ha : a ∈ pi s fun x => {True, False}),\n (fun t x a x => a ∈ t) ((fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a ha)\n (_ : (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) a ha ∈ powerset s) =\n a","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by ","nextTactic":"simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\n⊢ ∀ (a : (a : α) → a ∈ s → Prop),\n (∀ (a_1 : α) (h : a_1 ∈ s), a a_1 h = True ∨ a a_1 h ∈ {False}) →\n ∀ (a_1 : α) (a_2 : a_1 ∈ s), (a_1 ∈ s ∧ ∀ (h : a_1 ∈ s), a a_1 h) ↔ a a_1 a_2","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; ","nextTactic":"tauto","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\n⊢ ∀ (a : Finset α) (ha : a ∈ powerset s),\n (fun f x => filter (fun a => ∀ (h : a ∈ s), f a h) s) ((fun t x a x => a ∈ t) a ha)\n (_ : (fun t x a x => a ∈ t) a ha ∈ pi s fun x => {True, False}) =\n a","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by ","nextTactic":"simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝¹ : CommSemiring β\ninst✝ : DecidableEq α\nf g : α → β\ns : Finset α\n⊢ ∀ a ⊆ s, ∀ (a_1 : α), a_1 ∈ s ∧ (a_1 ∈ s → a_1 ∈ a) ↔ a_1 ∈ a","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; ","nextTactic":"tauto","declUpToTactic":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.142_0.3KYKAiUqy9KHW5V","decl":"/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommSemiring R\ninst✝ : LinearOrder ι\ns : Finset ι\nf g : ι → R\n⊢ ∏ i in s, (f i + g i) =\n ∏ i in s, f i +\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n ","nextTactic":"refine' Finset.induction_on_max s (by simp) _","declUpToTactic":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.175_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommSemiring R\ninst✝ : LinearOrder ι\ns : Finset ι\nf g : ι → R\n⊢ ∏ i in ∅, (f i + g i) =\n ∏ i in ∅, f i +\n ∑ i in ∅, (g i * ∏ j in filter (fun x => x < i) ∅, (f j + g j)) * ∏ j in filter (fun j => i < j) ∅, f j","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by ","nextTactic":"simp","declUpToTactic":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.175_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommSemiring R\ninst✝ : LinearOrder ι\ns : Finset ι\nf g : ι → R\n⊢ ∀ (a : ι) (s : Finset ι),\n (∀ x ∈ s, x < a) →\n ∏ i in s, (f i + g i) =\n ∏ i in s, f i +\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j →\n ∏ i in insert a s, (f i + g i) =\n ∏ i in insert a s, f i +\n ∑ i in insert a s,\n (g i * ∏ j in filter (fun x => x < i) (insert a s), (f j + g j)) *\n ∏ j in filter (fun j => i < j) (insert a s), f j","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n ","nextTactic":"clear s","declUpToTactic":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.175_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommSemiring R\ninst✝ : LinearOrder ι\nf g : ι → R\n⊢ ∀ (a : ι) (s : Finset ι),\n (∀ x ∈ s, x < a) →\n ∏ i in s, (f i + g i) =\n ∏ i in s, f i +\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j →\n ∏ i in insert a s, (f i + g i) =\n ∏ i in insert a s, f i +\n ∑ i in insert a s,\n (g i * ∏ j in filter (fun x => x < i) (insert a s), (f j + g j)) *\n ∏ j in filter (fun j => i < j) (insert a s), f j","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n ","nextTactic":"intro a s ha ihs","declUpToTactic":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.175_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommSemiring R\ninst✝ : LinearOrder ι\nf g : ι → R\na : ι\ns : Finset ι\nha : ∀ x ∈ s, x < a\nihs :\n ∏ i in s, (f i + g i) =\n ∏ i in s, f i +\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j\n⊢ ∏ i in insert a s, (f i + g i) =\n ∏ i in insert a s, f i +\n ∑ i in insert a s,\n (g i * ∏ j in filter (fun x => x < i) (insert a s), (f j + g j)) *\n ∏ j in filter (fun j => i < j) (insert a s), f j","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n ","nextTactic":"have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')","declUpToTactic":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.175_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommSemiring R\ninst✝ : LinearOrder ι\nf g : ι → R\na : ι\ns : Finset ι\nha : ∀ x ∈ s, x < a\nihs :\n ∏ i in s, (f i + g i) =\n ∏ i in s, f i +\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j\nha' : a ∉ s\n⊢ ∏ i in insert a s, (f i + g i) =\n ∏ i in insert a s, f i +\n ∑ i in insert a s,\n (g i * ∏ j in filter (fun x => x < i) (insert a s), (f j + g j)) *\n ∏ j in filter (fun j => i < j) (insert a s), f j","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n ","nextTactic":"rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]","declUpToTactic":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.175_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommSemiring R\ninst✝ : LinearOrder ι\nf g : ι → R\na : ι\ns : Finset ι\nha : ∀ x ∈ s, x < a\nihs :\n ∏ i in s, (f i + g i) =\n ∏ i in s, f i +\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j\nha' : a ∉ s\n⊢ f a * ∏ i in s, f i +\n (f a * ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j +\n (g a * ∏ i in s, f i +\n g a *\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j)) =\n f a * ∏ x in s, f x +\n ((g a * ∏ i in s, f i +\n g a *\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j) *\n ∏ j in filter (fun j => a < j) (insert a s), f j +\n ∑ x in s,\n (g x * ∏ j in filter (fun x_1 => x_1 < x) (insert a s), (f j + g j)) *\n ∏ j in filter (fun j => x < j) (insert a s), f j)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n ","nextTactic":"congr 1","declUpToTactic":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.175_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"case e_a\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommSemiring R\ninst✝ : LinearOrder ι\nf g : ι → R\na : ι\ns : Finset ι\nha : ∀ x ∈ s, x < a\nihs :\n ∏ i in s, (f i + g i) =\n ∏ i in s, f i +\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j\nha' : a ∉ s\n⊢ f a * ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j +\n (g a * ∏ i in s, f i +\n g a * ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j) =\n (g a * ∏ i in s, f i +\n g a *\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j) *\n ∏ j in filter (fun j => a < j) (insert a s), f j +\n ∑ x in s,\n (g x * ∏ j in filter (fun x_1 => x_1 < x) (insert a s), (f j + g j)) *\n ∏ j in filter (fun j => x < j) (insert a s), f j","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι���) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n ","nextTactic":"rw [add_comm]","declUpToTactic":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.175_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"case e_a\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommSemiring R\ninst✝ : LinearOrder ι\nf g : ι → R\na : ι\ns : Finset ι\nha : ∀ x ∈ s, x < a\nihs :\n ∏ i in s, (f i + g i) =\n ∏ i in s, f i +\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j\nha' : a ∉ s\n⊢ g a * ∏ i in s, f i +\n g a * ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j +\n f a * ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j =\n (g a * ∏ i in s, f i +\n g a *\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j) *\n ∏ j in filter (fun j => a < j) (insert a s), f j +\n ∑ x in s,\n (g x * ∏ j in filter (fun x_1 => x_1 < x) (insert a s), (f j + g j)) *\n ∏ j in filter (fun j => x < j) (insert a s), f j","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n ","nextTactic":"congr 1","declUpToTactic":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.175_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"case e_a.e_a\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommSemiring R\ninst✝ : LinearOrder ι\nf g : ι → R\na : ι\ns : Finset ι\nha : ∀ x ∈ s, x < a\nihs :\n ∏ i in s, (f i + g i) =\n ∏ i in s, f i +\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j\nha' : a ∉ s\n⊢ g a * ∏ i in s, f i +\n g a * ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j =\n (g a * ∏ i in s, f i +\n g a * ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j) *\n ∏ j in filter (fun j => a < j) (insert a s), f j","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · ","nextTactic":"rw [filter_false_of_mem, prod_empty, mul_one]","declUpToTactic":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.175_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"case e_a.e_a\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommSemiring R\ninst✝ : LinearOrder ι\nf g : ι → R\na : ι\ns : Finset ι\nha : ∀ x ∈ s, x < a\nihs :\n ∏ i in s, (f i + g i) =\n ∏ i in s, f i +\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j\nha' : a ∉ s\n⊢ ∀ x ∈ insert a s, ¬a < x","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n ","nextTactic":"exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩","declUpToTactic":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.175_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"case e_a.e_a\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommSemiring R\ninst✝ : LinearOrder ι\nf g : ι → R\na : ι\ns : Finset ι\nha : ∀ x ∈ s, x < a\nihs :\n ∏ i in s, (f i + g i) =\n ∏ i in s, f i +\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j\nha' : a ∉ s\n⊢ f a * ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j =\n ∑ x in s,\n (g x * ∏ j in filter (fun x_1 => x_1 < x) (insert a s), (f j + g j)) *\n ∏ j in filter (fun j => x < j) (insert a s), f j","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · ","nextTactic":"rw [mul_sum]","declUpToTactic":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.175_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"case e_a.e_a\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommSemiring R\ninst✝ : LinearOrder ι\nf g : ι → R\na : ι\ns : Finset ι\nha : ∀ x ∈ s, x < a\nihs :\n ∏ i in s, (f i + g i) =\n ∏ i in s, f i +\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j\nha' : a ∉ s\n⊢ ∑ x in s, f a * ((g x * ∏ j in filter (fun x_1 => x_1 < x) s, (f j + g j)) * ∏ j in filter (fun j => x < j) s, f j) =\n ∑ x in s,\n (g x * ∏ j in filter (fun x_1 => x_1 < x) (insert a s), (f j + g j)) *\n ∏ j in filter (fun j => x < j) (insert a s), f j","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n ","nextTactic":"refine' sum_congr rfl fun i hi => _","declUpToTactic":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.175_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"case e_a.e_a\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommSemiring R\ninst✝ : LinearOrder ι\nf g : ι → R\na : ι\ns : Finset ι\nha : ∀ x ∈ s, x < a\nihs :\n ∏ i in s, (f i + g i) =\n ∏ i in s, f i +\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j\nha' : a ∉ s\ni : ι\nhi : i ∈ s\n⊢ f a * ((g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j) =\n (g i * ∏ j in filter (fun x => x < i) (insert a s), (f j + g j)) * ∏ j in filter (fun j => i < j) (insert a s), f j","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n ","nextTactic":"rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]","declUpToTactic":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.175_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"case e_a.e_a\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na✝ : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommSemiring R\ninst✝ : LinearOrder ι\nf g : ι → R\na : ι\ns : Finset ι\nha : ∀ x ∈ s, x < a\nihs :\n ∏ i in s, (f i + g i) =\n ∏ i in s, f i +\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j + g j)) * ∏ j in filter (fun j => i < j) s, f j\nha' : a ∉ s\ni : ι\nhi : i ∈ s\n⊢ a ∉ filter (fun j => i < j) s","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n ","nextTactic":"exact mt (fun ha => (mem_filter.1 ha).1) ha'","declUpToTactic":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.175_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommRing R\ninst✝ : LinearOrder ι\ns : Finset ι\nf g : ι → R\n⊢ ∏ i in s, (f i - g i) =\n ∏ i in s, f i -\n ∑ i in s, (g i * ∏ j in filter (fun x => x < i) s, (f j - g j)) * ∏ j in filter (fun j => i < j) s, f j","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n ","nextTactic":"simp only [sub_eq_add_neg]","declUpToTactic":"/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.200_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommRing R\ninst✝ : LinearOrder ι\ns : Finset ι\nf g : ι → R\n⊢ ∏ x in s, (f x + -g x) =\n ∏ i in s, f i +\n -∑ x in s, (g x * ∏ x in filter (fun x_1 => x_1 < x) s, (f x + -g x)) * ∏ i in filter (fun j => x < j) s, f i","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n ","nextTactic":"convert prod_add_ordered s f fun i => -g i","declUpToTactic":"/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.200_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"case h.e'_3.h.e'_6\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommRing R\ninst✝ : LinearOrder ι\ns : Finset ι\nf g : ι → R\n⊢ -∑ x in s, (g x * ∏ x in filter (fun x_1 => x_1 < x) s, (f x + -g x)) * ∏ i in filter (fun j => x < j) s, f i =\n ∑ i in s, (-g i * ∏ j in filter (fun x => x < i) s, (f j + -g j)) * ∏ j in filter (fun j => i < j) s, f j","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n ","nextTactic":"simp","declUpToTactic":"/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.200_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommRing R\ninst✝ : LinearOrder ι\ns : Finset ι\nf : ι → R\n⊢ ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in filter (fun x => x < i) s, (1 - f j)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n ","nextTactic":"rw [prod_sub_ordered]","declUpToTactic":"/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.211_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝² : CommSemiring β\nι : Type u_1\nR : Type u_2\ninst✝¹ : CommRing R\ninst✝ : LinearOrder ι\ns : Finset ι\nf : ι → R\n⊢ ∏ i in s, 1 - ∑ i in s, (f i * ∏ j in filter (fun x => x < i) s, (1 - f j)) * ∏ j in filter (fun j => i < j) s, 1 =\n 1 - ∑ i in s, f i * ∏ j in filter (fun x => x < i) s, (1 - f j)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n �� have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n ","nextTactic":"simp","declUpToTactic":"/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.211_0.3KYKAiUqy9KHW5V","decl":"/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) "} +{"state":"α✝ : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α✝\na✝ : α✝\nb✝ : β\nf g : α✝ → β\ninst✝¹ : CommSemiring β\nα : Type u_1\nR : Type u_2\ninst✝ : CommSemiring R\na b : R\ns : Finset α\n⊢ ∑ t in powerset s, a ^ card t * b ^ (card s - card t) = (a + b) ^ card s","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n ","nextTactic":"classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]","declUpToTactic":"/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.219_0.3KYKAiUqy9KHW5V","decl":"/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card "} +{"state":"α✝ : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α✝\na✝ : α✝\nb✝ : β\nf g : α✝ → β\ninst✝¹ : CommSemiring β\nα : Type u_1\nR : Type u_2\ninst✝ : CommSemiring R\na b : R\ns : Finset α\n⊢ ∑ t in powerset s, a ^ card t * b ^ (card s - card t) = (a + b) ^ card s","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n ","nextTactic":"rw [← prod_const]","declUpToTactic":"/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.219_0.3KYKAiUqy9KHW5V","decl":"/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card "} +{"state":"α✝ : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α✝\na✝ : α✝\nb✝ : β\nf g : α✝ → β\ninst✝¹ : CommSemiring β\nα : Type u_1\nR : Type u_2\ninst✝ : CommSemiring R\na b : R\ns : Finset α\n⊢ ∑ t in powerset s, a ^ card t * b ^ (card s - card t) = ∏ _x in s, (a + b)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n ","nextTactic":"rw [prod_add]","declUpToTactic":"/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.219_0.3KYKAiUqy9KHW5V","decl":"/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card "} +{"state":"α✝ : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α✝\na✝ : α✝\nb✝ : β\nf g : α✝ → β\ninst✝¹ : CommSemiring β\nα : Type u_1\nR : Type u_2\ninst✝ : CommSemiring R\na b : R\ns : Finset α\n⊢ ∑ t in powerset s, a ^ card t * b ^ (card s - card t) = ∑ t in powerset s, (∏ a_1 in t, a) * ∏ a in s \\ t, b","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n ","nextTactic":"refine' Finset.sum_congr rfl fun t ht => _","declUpToTactic":"/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.219_0.3KYKAiUqy9KHW5V","decl":"/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card "} +{"state":"α✝ : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α✝\na✝ : α✝\nb✝ : β\nf g : α✝ → β\ninst✝¹ : CommSemiring β\nα : Type u_1\nR : Type u_2\ninst✝ : CommSemiring R\na b : R\ns t : Finset α\nht : t ∈ powerset s\n⊢ a ^ card t * b ^ (card s - card t) = (∏ a_1 in t, a) * ∏ a in s \\ t, b","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n ","nextTactic":"rw [prod_const]","declUpToTactic":"/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.219_0.3KYKAiUqy9KHW5V","decl":"/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card "} +{"state":"α✝ : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α✝\na✝ : α✝\nb✝ : β\nf g : α✝ → β\ninst✝¹ : CommSemiring β\nα : Type u_1\nR : Type u_2\ninst✝ : CommSemiring R\na b : R\ns t : Finset α\nht : t ∈ powerset s\n⊢ a ^ card t * b ^ (card s - card t) = a ^ card t * ∏ a in s \\ t, b","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n ","nextTactic":"rw [prod_const]","declUpToTactic":"/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.219_0.3KYKAiUqy9KHW5V","decl":"/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card "} +{"state":"α✝ : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α✝\na✝ : α✝\nb✝ : β\nf g : α✝ → β\ninst✝¹ : CommSemiring β\nα : Type u_1\nR : Type u_2\ninst✝ : CommSemiring R\na b : R\ns t : Finset α\nht : t ∈ powerset s\n⊢ a ^ card t * b ^ (card s - card t) = a ^ card t * b ^ card (s \\ t)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n ","nextTactic":"rw [← card_sdiff (mem_powerset.1 ht)]","declUpToTactic":"/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.219_0.3KYKAiUqy9KHW5V","decl":"/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns s₁ s₂ : Finset α\na : α\nb : β\nf g : α → β\nR : Type u_1\ninst✝ : CommRing R\nn k : ℕ\n⊢ ∏ i in range k, (↑n - ↑i) = ↑(∏ i in range k, (n - i))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x �� t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n ","nextTactic":"rw [prod_natCast]","declUpToTactic":"theorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.243_0.3KYKAiUqy9KHW5V","decl":"theorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns s₁ s₂ : Finset α\na : α\nb : β\nf g : α → β\nR : Type u_1\ninst✝ : CommRing R\nn k : ℕ\n⊢ ∏ i in range k, (↑n - ↑i) = ∏ x in range k, ↑(n - x)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n ","nextTactic":"rcases le_or_lt k n with hkn | hnk","declUpToTactic":"theorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.243_0.3KYKAiUqy9KHW5V","decl":"theorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) "} +{"state":"case inl\nα : Type u\nβ : Type v\nγ : Type w\ns s₁ s₂ : Finset α\na : α\nb : β\nf g : α → β\nR : Type u_1\ninst✝ : CommRing R\nn k : ℕ\nhkn : k ≤ n\n⊢ ∏ i in range k, (↑n - ↑i) = ∏ x in range k, ↑(n - x)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · ","nextTactic":"exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm","declUpToTactic":"theorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.243_0.3KYKAiUqy9KHW5V","decl":"theorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) "} +{"state":"case inr\nα : Type u\nβ : Type v\nγ : Type w\ns s₁ s₂ : Finset α\na : α\nb : β\nf g : α → β\nR : Type u_1\ninst✝ : CommRing R\nn k : ℕ\nhnk : n < k\n⊢ ∏ i in range k, (↑n - ↑i) = ∏ x in range k, ↑(n - x)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · ","nextTactic":"rw [← mem_range] at hnk","declUpToTactic":"theorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.243_0.3KYKAiUqy9KHW5V","decl":"theorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) "} +{"state":"case inr\nα : Type u\nβ : Type v\nγ : Type w\ns s₁ s₂ : Finset α\na : α\nb : β\nf g : α → β\nR : Type u_1\ninst✝ : CommRing R\nn k : ℕ\nhnk : n ∈ range k\n⊢ ∏ i in range k, (↑n - ↑i) = ∏ x in range k, ↑(n - x)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n ","nextTactic":"rw [prod_eq_zero hnk, prod_eq_zero hnk]","declUpToTactic":"theorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.243_0.3KYKAiUqy9KHW5V","decl":"theorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) "} +{"state":"case inr\nα : Type u\nβ : Type v\nγ : Type w\ns s₁ s₂ : Finset α\na : α\nb : β\nf g : α → β\nR : Type u_1\ninst✝ : CommRing R\nn k : ℕ\nhnk : n ∈ range k\n⊢ ↑(n - n) = 0","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> ","nextTactic":"simp","declUpToTactic":"theorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.243_0.3KYKAiUqy9KHW5V","decl":"theorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) "} +{"state":"case inr\nα : Type u\nβ : Type v\nγ : Type w\ns s₁ s₂ : Finset α\na : α\nb : β\nf g : α → β\nR : Type u_1\ninst✝ : CommRing R\nn k : ℕ\nhnk : n ∈ range k\n⊢ ↑n - ↑n = 0","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> ","nextTactic":"simp","declUpToTactic":"theorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.243_0.3KYKAiUqy9KHW5V","decl":"theorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝¹ : DecidableEq α\ninst✝ : CommMonoid β\ns : Finset α\nx : α\nh : x ∉ s\nf : Finset α → β\n⊢ ∏ a in powerset (insert x s), f a = (∏ a in powerset s, f a) * ∏ t in powerset s, f (insert x t)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> simp\n#align finset.prod_range_cast_nat_sub Finset.prod_range_cast_nat_sub\n\nend CommRing\n\n/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n ","nextTactic":"rw [powerset_insert]","declUpToTactic":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.254_0.3KYKAiUqy9KHW5V","decl":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝¹ : DecidableEq α\ninst✝ : CommMonoid β\ns : Finset α\nx : α\nh : x ∉ s\nf : Finset α → β\n⊢ ∏ a in powerset s ∪ image (insert x) (powerset s), f a = (∏ a in powerset s, f a) * ∏ t in powerset s, f (insert x t)","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> simp\n#align finset.prod_range_cast_nat_sub Finset.prod_range_cast_nat_sub\n\nend CommRing\n\n/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n ","nextTactic":"rw [Finset.prod_union]","declUpToTactic":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.254_0.3KYKAiUqy9KHW5V","decl":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝¹ : DecidableEq α\ninst✝ : CommMonoid β\ns : Finset α\nx : α\nh : x ∉ s\nf : Finset α → β\n⊢ (∏ x in powerset s, f x) * ∏ x in image (insert x) (powerset s), f x =\n (∏ a in powerset s, f a) * ∏ t in powerset s, f (insert x t)\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝¹ : DecidableEq α\ninst✝ : CommMonoid β\ns : Finset α\nx : α\nh : x ∉ s\nf : Finset α → β\n⊢ Disjoint (powerset s) (image (insert x) (powerset s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> simp\n#align finset.prod_range_cast_nat_sub Finset.prod_range_cast_nat_sub\n\nend CommRing\n\n/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n ","nextTactic":"rw [Finset.prod_image]","declUpToTactic":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.254_0.3KYKAiUqy9KHW5V","decl":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝¹ : DecidableEq α\ninst✝ : CommMonoid β\ns : Finset α\nx : α\nh : x ∉ s\nf : Finset α → β\n⊢ ∀ x_1 ∈ powerset s, ∀ y ∈ powerset s, insert x x_1 = insert x y → x_1 = y","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> simp\n#align finset.prod_range_cast_nat_sub Finset.prod_range_cast_nat_sub\n\nend CommRing\n\n/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · ","nextTactic":"intro t₁ h₁ t₂ h₂ heq","declUpToTactic":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.254_0.3KYKAiUqy9KHW5V","decl":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝¹ : DecidableEq α\ninst✝ : CommMonoid β\ns : Finset α\nx : α\nh : x ∉ s\nf : Finset α → β\nt₁ : Finset α\nh₁ : t₁ ∈ powerset s\nt₂ : Finset α\nh₂ : t₂ ∈ powerset s\nheq : insert x t₁ = insert x t₂\n⊢ t₁ = t₂","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> simp\n#align finset.prod_range_cast_nat_sub Finset.prod_range_cast_nat_sub\n\nend CommRing\n\n/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · intro t₁ h₁ t₂ h₂ heq\n ","nextTactic":"rw [← Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h), ←\n Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq]","declUpToTactic":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · intro t₁ h₁ t₂ h₂ heq\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.254_0.3KYKAiUqy9KHW5V","decl":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝¹ : DecidableEq α\ninst✝ : CommMonoid β\ns : Finset α\nx : α\nh : x ∉ s\nf : Finset α → β\n⊢ Disjoint (powerset s) (image (insert x) (powerset s))","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> simp\n#align finset.prod_range_cast_nat_sub Finset.prod_range_cast_nat_sub\n\nend CommRing\n\n/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · intro t₁ h₁ t₂ h₂ heq\n rw [← Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h), ←\n Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq]\n · ","nextTactic":"rw [Finset.disjoint_iff_ne]","declUpToTactic":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · intro t₁ h₁ t₂ h₂ heq\n rw [← Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h), ←\n Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq]\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.254_0.3KYKAiUqy9KHW5V","decl":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝¹ : DecidableEq α\ninst✝ : CommMonoid β\ns : Finset α\nx : α\nh : x ∉ s\nf : Finset α → β\n⊢ ∀ a ∈ powerset s, ∀ b ∈ image (insert x) (powerset s), a ≠ b","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> simp\n#align finset.prod_range_cast_nat_sub Finset.prod_range_cast_nat_sub\n\nend CommRing\n\n/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · intro t₁ h₁ t₂ h₂ heq\n rw [← Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h), ←\n Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq]\n · rw [Finset.disjoint_iff_ne]\n ","nextTactic":"intro t₁ h₁ t₂ h₂","declUpToTactic":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · intro t₁ h₁ t₂ h₂ heq\n rw [← Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h), ←\n Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq]\n · rw [Finset.disjoint_iff_ne]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.254_0.3KYKAiUqy9KHW5V","decl":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝¹ : DecidableEq α\ninst✝ : CommMonoid β\ns : Finset α\nx : α\nh : x ∉ s\nf : Finset α → β\nt₁ : Finset α\nh₁ : t₁ ∈ powerset s\nt₂ : Finset α\nh₂ : t₂ ∈ image (insert x) (powerset s)\n⊢ t₁ ≠ t₂","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> simp\n#align finset.prod_range_cast_nat_sub Finset.prod_range_cast_nat_sub\n\nend CommRing\n\n/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · intro t₁ h₁ t₂ h₂ heq\n rw [← Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h), ←\n Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq]\n · rw [Finset.disjoint_iff_ne]\n intro t₁ h₁ t₂ h₂\n ","nextTactic":"rcases Finset.mem_image.1 h₂ with ⟨t₃, _h₃, H₃₂⟩","declUpToTactic":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · intro t₁ h₁ t₂ h₂ heq\n rw [← Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h), ←\n Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq]\n · rw [Finset.disjoint_iff_ne]\n intro t₁ h₁ t₂ h₂\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.254_0.3KYKAiUqy9KHW5V","decl":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) "} +{"state":"case intro.intro\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝¹ : DecidableEq α\ninst✝ : CommMonoid β\ns : Finset α\nx : α\nh : x ∉ s\nf : Finset α → β\nt₁ : Finset α\nh₁ : t₁ ∈ powerset s\nt₂ : Finset α\nh₂ : t₂ ∈ image (insert x) (powerset s)\nt₃ : Finset α\n_h₃ : t₃ ∈ powerset s\nH₃₂ : insert x t₃ = t₂\n⊢ t₁ ≠ t₂","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> simp\n#align finset.prod_range_cast_nat_sub Finset.prod_range_cast_nat_sub\n\nend CommRing\n\n/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · intro t₁ h₁ t₂ h₂ heq\n rw [← Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h), ←\n Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq]\n · rw [Finset.disjoint_iff_ne]\n intro t₁ h₁ t₂ h₂\n rcases Finset.mem_image.1 h₂ with ⟨t₃, _h₃, H₃₂⟩\n ","nextTactic":"rw [← H₃₂]","declUpToTactic":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ��� t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · intro t₁ h₁ t₂ h₂ heq\n rw [← Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h), ←\n Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq]\n · rw [Finset.disjoint_iff_ne]\n intro t₁ h₁ t₂ h₂\n rcases Finset.mem_image.1 h₂ with ⟨t₃, _h₃, H₃₂⟩\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.254_0.3KYKAiUqy9KHW5V","decl":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) "} +{"state":"case intro.intro\nα : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝¹ : DecidableEq α\ninst✝ : CommMonoid β\ns : Finset α\nx : α\nh : x ∉ s\nf : Finset α → β\nt₁ : Finset α\nh₁ : t₁ ∈ powerset s\nt₂ : Finset α\nh₂ : t₂ ∈ image (insert x) (powerset s)\nt₃ : Finset α\n_h₃ : t₃ ∈ powerset s\nH₃₂ : insert x t₃ = t₂\n⊢ t₁ ≠ insert x t₃","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> simp\n#align finset.prod_range_cast_nat_sub Finset.prod_range_cast_nat_sub\n\nend CommRing\n\n/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · intro t₁ h₁ t₂ h₂ heq\n rw [← Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h), ←\n Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq]\n · rw [Finset.disjoint_iff_ne]\n intro t₁ h₁ t₂ h₂\n rcases Finset.mem_image.1 h₂ with ⟨t₃, _h₃, H₃₂⟩\n rw [← H₃₂]\n ","nextTactic":"exact ne_insert_of_not_mem _ _ (not_mem_of_mem_powerset_of_not_mem h₁ h)","declUpToTactic":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · intro t₁ h₁ t₂ h₂ heq\n rw [← Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h), ←\n Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq]\n · rw [Finset.disjoint_iff_ne]\n intro t₁ h₁ t₂ h₂\n rcases Finset.mem_image.1 h₂ with ⟨t₃, _h₃, H₃₂⟩\n rw [← H₃₂]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.254_0.3KYKAiUqy9KHW5V","decl":"/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝ : CommMonoid β\ns : Finset α\nf : Finset α → β\n⊢ ∏ t in powerset s, f t = ∏ j in range (card s + 1), ∏ t in powersetCard j s, f t","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> simp\n#align finset.prod_range_cast_nat_sub Finset.prod_range_cast_nat_sub\n\nend CommRing\n\n/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · intro t₁ h₁ t₂ h₂ heq\n rw [← Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h), ←\n Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq]\n · rw [Finset.disjoint_iff_ne]\n intro t₁ h₁ t₂ h₂\n rcases Finset.mem_image.1 h₂ with ⟨t₃, _h₃, H₃₂⟩\n rw [← H₃₂]\n exact ne_insert_of_not_mem _ _ (not_mem_of_mem_powerset_of_not_mem h₁ h)\n#align finset.prod_powerset_insert Finset.prod_powerset_insert\n#align finset.sum_powerset_insert Finset.sum_powerset_insert\n\n/-- A product over `powerset s` is equal to the double product over sets of subsets of `s` with\n`card s = k`, for `k = 1, ..., card s`. -/\n@[to_additive\n \"A sum over `powerset s` is equal to the double sum over sets of subsets of `s` with\n `card s = k`, for `k = 1, ..., card s`\"]\ntheorem prod_powerset [CommMonoid β] (s : Finset α) (f : Finset α → β) :\n ∏ t in powerset s, f t = ∏ j in range (card s + 1), ∏ t in powersetCard j s, f t := by\n ","nextTactic":"rw [powerset_card_disjiUnion]","declUpToTactic":"/-- A product over `powerset s` is equal to the double product over sets of subsets of `s` with\n`card s = k`, for `k = 1, ..., card s`. -/\n@[to_additive\n \"A sum over `powerset s` is equal to the double sum over sets of subsets of `s` with\n `card s = k`, for `k = 1, ..., card s`\"]\ntheorem prod_powerset [CommMonoid β] (s : Finset α) (f : Finset α → β) :\n ∏ t in powerset s, f t = ∏ j in range (card s + 1), ∏ t in powersetCard j s, f t := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.277_0.3KYKAiUqy9KHW5V","decl":"/-- A product over `powerset s` is equal to the double product over sets of subsets of `s` with\n`card s = k`, for `k = 1, ..., card s`. -/\n@[to_additive\n \"A sum over `powerset s` is equal to the double sum over sets of subsets of `s` with\n `card s = k`, for `k = 1, ..., card s`\"]\ntheorem prod_powerset [CommMonoid β] (s : Finset α) (f : Finset α → β) :\n ∏ t in powerset s, f t = ∏ j in range (card s + 1), ∏ t in powersetCard j s, f t "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns✝ s₁ s₂ : Finset α\na : α\nb : β\nf✝ g : α → β\ninst✝ : CommMonoid β\ns : Finset α\nf : Finset α → β\n⊢ ∏ t in\n disjiUnion (range (card s + 1)) (fun i => powersetCard i s)\n (_ : Set.Pairwise ↑(range (card s + 1)) fun i j => Disjoint (powersetCard i s) (powersetCard j s)),\n f t =\n ∏ j in range (card s + 1), ∏ t in powersetCard j s, f t","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> simp\n#align finset.prod_range_cast_nat_sub Finset.prod_range_cast_nat_sub\n\nend CommRing\n\n/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · intro t₁ h₁ t₂ h₂ heq\n rw [← Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h), ←\n Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq]\n · rw [Finset.disjoint_iff_ne]\n intro t₁ h₁ t₂ h₂\n rcases Finset.mem_image.1 h₂ with ⟨t₃, _h₃, H₃₂⟩\n rw [← H₃₂]\n exact ne_insert_of_not_mem _ _ (not_mem_of_mem_powerset_of_not_mem h₁ h)\n#align finset.prod_powerset_insert Finset.prod_powerset_insert\n#align finset.sum_powerset_insert Finset.sum_powerset_insert\n\n/-- A product over `powerset s` is equal to the double product over sets of subsets of `s` with\n`card s = k`, for `k = 1, ..., card s`. -/\n@[to_additive\n \"A sum over `powerset s` is equal to the double sum over sets of subsets of `s` with\n `card s = k`, for `k = 1, ..., card s`\"]\ntheorem prod_powerset [CommMonoid β] (s : Finset α) (f : Finset α → β) :\n ∏ t in powerset s, f t = ∏ j in range (card s + 1), ∏ t in powersetCard j s, f t := by\n rw [powerset_card_disjiUnion]\n ","nextTactic":"rw [prod_disjiUnion]","declUpToTactic":"/-- A product over `powerset s` is equal to the double product over sets of subsets of `s` with\n`card s = k`, for `k = 1, ..., card s`. -/\n@[to_additive\n \"A sum over `powerset s` is equal to the double sum over sets of subsets of `s` with\n `card s = k`, for `k = 1, ..., card s`\"]\ntheorem prod_powerset [CommMonoid β] (s : Finset α) (f : Finset α → β) :\n ∏ t in powerset s, f t = ∏ j in range (card s + 1), ∏ t in powersetCard j s, f t := by\n rw [powerset_card_disjiUnion]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.277_0.3KYKAiUqy9KHW5V","decl":"/-- A product over `powerset s` is equal to the double product over sets of subsets of `s` with\n`card s = k`, for `k = 1, ..., card s`. -/\n@[to_additive\n \"A sum over `powerset s` is equal to the double sum over sets of subsets of `s` with\n `card s = k`, for `k = 1, ..., card s`\"]\ntheorem prod_powerset [CommMonoid β] (s : Finset ��) (f : Finset α → β) :\n ∏ t in powerset s, f t = ∏ j in range (card s + 1), ∏ t in powersetCard j s, f t "} +{"state":"α : Type u\nβ : Type v\nγ : Type w\ns s₁ s₂ : Finset α\na : α\nb : β\nf✝ g✝ : α → β\ninst✝ : NonUnitalNonAssocSemiring β\nn k : ℕ\nf g : ℕ → β\n⊢ (∑ i in range (n + 1), f i) * ∑ i in range (k + 1), g i =\n (∑ i in range n, f i) * ∑ i in range k, g i + f n * ∑ i in range k, g i + (∑ i in range n, f i) * g k + f n * g k","srcUpToTactic":"/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Algebra.Field.Defs\nimport Mathlib.Data.Finset.Pi\nimport Mathlib.Data.Finset.Powerset\n\n#align_import algebra.big_operators.ring from \"leanprover-community/mathlib\"@\"b2c89893177f66a48daf993b7ba5ef7cddeff8c9\"\n\n/-!\n# Results about big operators with values in a (semi)ring\n\nWe prove results about big operators that involve some interaction between\nmultiplicative and additive structures on the values being combined.\n-/\n\n\nuniverse u v w\n\nopen BigOperators\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace Finset\n\nvariable {s s₁ s₂ : Finset α} {a : α} {b : β} {f g : α → β}\n\nsection CommMonoid\n\nvariable [CommMonoid β]\n\nopen Classical\n\ntheorem prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :\n ∀ {s : Finset α}, ∏ i in s, x ^ f i = x ^ ∑ x in s, f x := by\n apply Finset.induction\n · simp\n · intro a s has H\n rw [Finset.prod_insert has]\n rw [Finset.sum_insert has]\n rw [pow_add]\n rw [H]\n#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum\n\nend CommMonoid\n\nsection Semiring\n\nvariable [NonUnitalNonAssocSemiring β]\n\ntheorem sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=\n map_sum (AddMonoidHom.mulRight b) _ s\n#align finset.sum_mul Finset.sum_mul\n\ntheorem mul_sum : (b * ∑ x in s, f x) = ∑ x in s, b * f x :=\n map_sum (AddMonoidHom.mulLeft b) _ s\n#align finset.mul_sum Finset.mul_sum\n\ntheorem sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : Finset ι₁) (s₂ : Finset ι₂) (f₁ : ι₁ → β)\n (f₂ : ι₂ → β) :\n ((∑ x₁ in s₁, f₁ x₁) * ∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 := by\n rw [sum_product]\n rw [sum_mul]\n rw [sum_congr rfl]\n intros\n rw [mul_sum]\n#align finset.sum_mul_sum Finset.sum_mul_sum\n\nend Semiring\n\nsection Semiring\n\ntheorem dvd_sum [NonUnitalSemiring β]\n {b : β} {s : Finset α} {f : α → β} (h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=\n Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx\n#align finset.dvd_sum Finset.dvd_sum\n\nvariable [NonAssocSemiring β]\n\ntheorem sum_mul_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, f x * ite (a = x) 1 0) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_mul_boole Finset.sum_mul_boole\n\ntheorem sum_boole_mul [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :\n (∑ x in s, ite (a = x) 1 0 * f x) = ite (a ∈ s) (f a) 0 := by simp\n#align finset.sum_boole_mul Finset.sum_boole_mul\n\nend Semiring\n\ntheorem sum_div [DivisionSemiring β] {s : Finset α} {f : α → β} {b : β} :\n (∑ x in s, f x) / b = ∑ x in s, f x / b := by simp only [div_eq_mul_inv, sum_mul]\n#align finset.sum_div Finset.sum_div\n\nsection CommSemiring\n\nvariable [CommSemiring β]\n\n/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.\n `Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/\ntheorem prod_sum {δ : α → Type*} [DecidableEq α] [∀ a, DecidableEq (δ a)] {s : Finset α}\n {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a → β} :\n (∏ a in s, ∑ b in t a, f a b) = ∑ p in s.pi t, ∏ x in s.attach, f x.1 (p x.1 x.2) := by\n induction' s using Finset.induction with a s ha ih\n · rw [pi_empty, sum_singleton]\n rfl\n · have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →\n Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by\n intro x _ y _ h\n simp only [disjoint_iff_ne, mem_image]\n rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq\n have : Pi.cons s a x p₂ a (mem_insert_self _ _)\n = Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]\n rw [Pi.cons_same] at this\n rw [Pi.cons_same] at this\n exact h this\n rw [prod_insert ha]\n rw [pi_insert ha]\n rw [ih]\n rw [sum_mul]\n rw [sum_biUnion h₁]\n refine' sum_congr rfl fun b _ => _\n have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=\n fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq\n rw [sum_image h₂]\n rw [mul_sum]\n refine' sum_congr rfl fun g _ => _\n rw [attach_insert]\n rw [prod_insert]\n rw [prod_image]\n · simp only [Pi.cons_same]\n congr with ⟨v, hv⟩\n congr\n exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm\n · exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj\n · simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,\n Subtype.exists, exists_prop, exists_eq_right] using ha\n#align finset.prod_sum Finset.prod_sum\n\n/-- The product of `f a + g a` over all of `s` is the sum\n over the powerset of `s` of the product of `f` over a subset `t` times\n the product of `g` over the complement of `t` -/\ntheorem prod_add [DecidableEq α] (f g : α → β) (s : Finset α) :\n ∏ a in s, (f a + g a) = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a := by\n classical\n calc\n ∏ a in s, (f a + g a) =\n ∏ a in s, ∑ p in ({True, False} : Finset Prop), if p then f a else g a := by simp\n _ = ∑ p in (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),\n ∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 :=\n prod_sum\n _ = ∑ t in s.powerset, (∏ a in t, f a) * ∏ a in s \\ t, g a :=\n sum_bij'\n (fun f _ => s.filter (fun a => ∀ h : a ∈ s, f a h))\n (by simp)\n (fun a _ => by\n rw [prod_ite]\n congr 1\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_filter.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp)\n exact prod_bij'\n (fun a _ => a.1) (by simp) (by simp)\n (fun a ha => ⟨a, (mem_sdiff.1 ha).1⟩) (fun a ha => by simp at ha; simp; tauto)\n (by simp) (by simp))\n (fun t _ a _ => a ∈ t)\n (by simp [Classical.em])\n (by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)\n (by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)\n#align finset.prod_add Finset.prod_add\n\n/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/\ntheorem prod_add_ordered {ι R : Type*} [CommSemiring R] [LinearOrder ι] (s : Finset ι)\n (f g : ι → R) :\n ∏ i in s, (f i + g i) =\n (∏ i in s, f i) +\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j + g j)) * ∏ j in s.filter fun j => i < j, f j := by\n refine' Finset.induction_on_max s (by simp) _\n clear s\n intro a s ha ihs\n have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')\n rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),\n filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]\n congr 1\n rw [add_comm]\n congr 1\n · rw [filter_false_of_mem, prod_empty, mul_one]\n exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩\n · rw [mul_sum]\n refine' sum_congr rfl fun i hi => _\n rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,\n mul_left_comm]\n exact mt (fun ha => (mem_filter.1 ha).1) ha'\n#align finset.prod_add_ordered Finset.prod_add_ordered\n\n/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/\ntheorem prod_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι) (f g : ι → R) :\n ∏ i in s, (f i - g i) =\n (∏ i in s, f i) -\n ∑ i in s,\n g i * (∏ j in s.filter (· < i), (f j - g j)) * ∏ j in s.filter fun j => i < j, f j := by\n simp only [sub_eq_add_neg]\n convert prod_add_ordered s f fun i => -g i\n simp\n#align finset.prod_sub_ordered Finset.prod_sub_ordered\n\n/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of\na partition of unity from a collection of “bump” functions. -/\ntheorem prod_one_sub_ordered {ι R : Type*} [CommRing R] [LinearOrder ι] (s : Finset ι)\n (f : ι → R) : ∏ i in s, (1 - f i) = 1 - ∑ i in s, f i * ∏ j in s.filter (· < i), (1 - f j) := by\n rw [prod_sub_ordered]\n simp\n#align finset.prod_one_sub_ordered Finset.prod_one_sub_ordered\n\n/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`\ngives `(a + b)^s.card`.-/\ntheorem sum_pow_mul_eq_add_pow {α R : Type*} [CommSemiring R] (a b : R) (s : Finset α) :\n (∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by\n classical\n rw [← prod_const]\n rw [prod_add]\n refine' Finset.sum_congr rfl fun t ht => _\n rw [prod_const]\n rw [prod_const]\n rw [← card_sdiff (mem_powerset.1 ht)]\n#align finset.sum_pow_mul_eq_add_pow Finset.sum_pow_mul_eq_add_pow\n\n@[norm_cast]\ntheorem prod_natCast (s : Finset α) (f : α → ℕ) : ↑(∏ x in s, f x : ℕ) = ∏ x in s, (f x : β) :=\n (Nat.castRingHom β).map_prod f s\n#align finset.prod_nat_cast Finset.prod_natCast\n\nend CommSemiring\n\nsection CommRing\n\nvariable {R : Type*} [CommRing R]\n\ntheorem prod_range_cast_nat_sub (n k : ℕ) :\n ∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) := by\n rw [prod_natCast]\n rcases le_or_lt k n with hkn | hnk\n · exact prod_congr rfl fun i hi => (Nat.cast_sub <| (mem_range.1 hi).le.trans hkn).symm\n · rw [← mem_range] at hnk\n rw [prod_eq_zero hnk, prod_eq_zero hnk] <;> simp\n#align finset.prod_range_cast_nat_sub Finset.prod_range_cast_nat_sub\n\nend CommRing\n\n/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets\nof `s`, and over all subsets of `s` to which one adds `x`. -/\n@[to_additive\n \"A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets\n of `s`, and over all subsets of `s` to which one adds `x`.\"]\ntheorem prod_powerset_insert [DecidableEq α] [CommMonoid β] {s : Finset α} {x : α} (h : x ∉ s)\n (f : Finset α → β) :\n (∏ a in (insert x s).powerset, f a) =\n (∏ a in s.powerset, f a) * ∏ t in s.powerset, f (insert x t) := by\n rw [powerset_insert]\n rw [Finset.prod_union]\n rw [Finset.prod_image]\n · intro t₁ h₁ t₂ h₂ heq\n rw [← Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h), ←\n Finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq]\n · rw [Finset.disjoint_iff_ne]\n intro t₁ h₁ t₂ h₂\n rcases Finset.mem_image.1 h₂ with ⟨t₃, _h₃, H₃₂⟩\n rw [← H₃₂]\n exact ne_insert_of_not_mem _ _ (not_mem_of_mem_powerset_of_not_mem h₁ h)\n#align finset.prod_powerset_insert Finset.prod_powerset_insert\n#align finset.sum_powerset_insert Finset.sum_powerset_insert\n\n/-- A product over `powerset s` is equal to the double product over sets of subsets of `s` with\n`card s = k`, for `k = 1, ..., card s`. -/\n@[to_additive\n \"A sum over `powerset s` is equal to the double sum over sets of subsets of `s` with\n `card s = k`, for `k = 1, ..., card s`\"]\ntheorem prod_powerset [CommMonoid β] (s : Finset α) (f : Finset α → β) :\n ∏ t in powerset s, f t = ∏ j in range (card s + 1), ∏ t in powersetCard j s, f t := by\n rw [powerset_card_disjiUnion]\n rw [prod_disjiUnion]\n#align finset.prod_powerset Finset.prod_powerset\n#align finset.sum_powerset Finset.sum_powerset\n\ntheorem sum_range_succ_mul_sum_range_succ [NonUnitalNonAssocSemiring β] (n k : ℕ) (f g : ℕ → β) :\n ((∑ i in range (n + 1), f i) * ∑ i in range (k + 1), g i) =\n (((∑ i in range n, f i) * ∑ i in range k, g i) + f n * ∑ i in range k, g i) +\n (∑ i in range n, f i) * g k +\n f n * g k := by\n ","nextTactic":"simp only [add_mul, mul_add, add_assoc, sum_range_succ]","declUpToTactic":"theorem sum_range_succ_mul_sum_range_succ [NonUnitalNonAssocSemiring β] (n k : ℕ) (f g : ℕ → β) :\n ((∑ i in range (n + 1), f i) * ∑ i in range (k + 1), g i) =\n (((∑ i in range n, f i) * ∑ i in range k, g i) + f n * ∑ i in range k, g i) +\n (∑ i in range n, f i) * g k +\n f n * g k := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Ring.289_0.3KYKAiUqy9KHW5V","decl":"theorem sum_range_succ_mul_sum_range_succ [NonUnitalNonAssocSemiring β] (n k : ℕ) (f g : ℕ → β) :\n ((∑ i in range (n + 1), f i) * ∑ i in range (k + 1), g i) =\n (((∑ i in range n, f i) * ∑ i in range k, g i) + f n * ∑ i in range k, g i) +\n (∑ i in range n, f i) * g k +\n f n * g k "}