diff --git "a/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_BigOperators_Order.jsonl" "b/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_BigOperators_Order.jsonl" new file mode 100644--- /dev/null +++ "b/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_BigOperators_Order.jsonl" @@ -0,0 +1,172 @@ +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf : M → N\np : M → Prop\nh_mul : ∀ (x y : M), p x → p y → f (x * y) ≤ f x * f y\nhp_mul : ∀ (x y : M), p x → p y → p (x * y)\ng : ι → M\ns : Finset ι\nhs_nonempty : Finset.Nonempty s\nhs : ∀ i ∈ s, p (g i)\n⊢ f (∏ i in s, g i) ≤ ∏ i in s, f (g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n ","nextTactic":"refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _","declUpToTactic":"/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.33_0.RJ9z80YJpu1cs9E","decl":"/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) "} +{"state":"case refine'_1\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf : M → N\np : M → Prop\nh_mul : ∀ (x y : M), p x → p y → f (x * y) ≤ f x * f y\nhp_mul : ∀ (x y : M), p x → p y → p (x * y)\ng : ι → M\ns : Finset ι\nhs_nonempty : Finset.Nonempty s\nhs : ∀ i ∈ s, p (g i)\n⊢ Multiset.map (fun i => g i) s.val ≠ ∅","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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · ","nextTactic":"simp [hs_nonempty.ne_empty]","declUpToTactic":"/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.33_0.RJ9z80YJpu1cs9E","decl":"/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf : M → N\np : M → Prop\nh_mul : ∀ (x y : M), p x → p y → f (x * y) ≤ f x * f y\nhp_mul : ∀ (x y : M), p x → p y → p (x * y)\ng : ι → M\ns : Finset ι\nhs_nonempty : Finset.Nonempty s\nhs : ∀ i ∈ s, p (g i)\n⊢ ∀ a ∈ Multiset.map (fun i => g i) s.val, p 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · ","nextTactic":"exact Multiset.forall_mem_map_iff.mpr hs","declUpToTactic":"/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.33_0.RJ9z80YJpu1cs9E","decl":"/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) "} +{"state":"case refine'_3\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf : M → N\np : M → Prop\nh_mul : ∀ (x y : M), p x → p y → f (x * y) ≤ f x * f y\nhp_mul : ∀ (x y : M), p x → p y → p (x * y)\ng : ι → M\ns : Finset ι\nhs_nonempty : Finset.Nonempty s\nhs : ∀ i ∈ s, p (g i)\n⊢ Multiset.prod (Multiset.map f (Multiset.map (fun i => g i) s.val)) ≤ ∏ i in s, f (g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n ","nextTactic":"rw [Multiset.map_map]","declUpToTactic":"/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.33_0.RJ9z80YJpu1cs9E","decl":"/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) "} +{"state":"case refine'_3\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf : M → N\np : M → Prop\nh_mul : ∀ (x y : M), p x → p y → f (x * y) ≤ f x * f y\nhp_mul : ∀ (x y : M), p x → p y → p (x * y)\ng : ι → M\ns : Finset ι\nhs_nonempty : Finset.Nonempty s\nhs : ∀ i ∈ s, p (g i)\n⊢ Multiset.prod (Multiset.map (f ∘ fun i => g i) s.val) ≤ ∏ i in s, f (g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n ","nextTactic":"rfl","declUpToTactic":"/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.33_0.RJ9z80YJpu1cs9E","decl":"/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf : M → N\np : M → Prop\nh_one : f 1 = 1\nh_mul : ∀ (x y : M), p x → p y → f (x * y) ≤ f x * f y\nhp_mul : ∀ (x y : M), p x → p y → p (x * y)\ng : ι → M\ns : Finset ι\nhs : ∀ i ∈ s, p (g i)\n⊢ f (∏ i in s, g i) ≤ ∏ i in s, f (g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n ","nextTactic":"rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)","declUpToTactic":"/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.70_0.RJ9z80YJpu1cs9E","decl":"/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) "} +{"state":"case inl\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf : M → N\np : M → Prop\nh_one : f 1 = 1\nh_mul : ∀ (x y : M), p x → p y → f (x * y) ≤ f x * f y\nhp_mul : ∀ (x y : M), p x → p y → p (x * y)\ng : ι → M\nhs : ∀ i ∈ ∅, p (g i)\n⊢ f (∏ i in ∅, g i) ≤ ∏ i in ∅, f (g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · ","nextTactic":"simp [h_one]","declUpToTactic":"/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.70_0.RJ9z80YJpu1cs9E","decl":"/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) "} +{"state":"case inr\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf : M → N\np : M → Prop\nh_one : f 1 = 1\nh_mul : ∀ (x y : M), p x → p y → f (x * y) ≤ f x * f y\nhp_mul : ∀ (x y : M), p x → p y → p (x * y)\ng : ι → M\ns : Finset ι\nhs : ∀ i ∈ s, p (g i)\nhs_nonempty : Finset.Nonempty s\n⊢ f (∏ i in s, g i) ≤ ∏ i in s, f (g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) �� f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · ","nextTactic":"exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs","declUpToTactic":"/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.70_0.RJ9z80YJpu1cs9E","decl":"/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf : M → N\nh_one : f 1 = 1\nh_mul : ∀ (x y : M), f (x * y) ≤ f x * f y\ns : Finset ι\ng : ι → M\n⊢ f (∏ i in s, g i) ≤ ∏ i in s, f (g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n ","nextTactic":"refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _","declUpToTactic":"/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.90_0.RJ9z80YJpu1cs9E","decl":"/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf : M → N\nh_one : f 1 = 1\nh_mul : ∀ (x y : M), f (x * y) ≤ f x * f y\ns : Finset ι\ng : ι → M\n⊢ Multiset.prod (Multiset.map f (Multiset.map (fun i => g i) s.val)) ≤ ∏ i in s, f (g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ��� s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n ","nextTactic":"rw [Multiset.map_map]","declUpToTactic":"/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.90_0.RJ9z80YJpu1cs9E","decl":"/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf : M → N\nh_one : f 1 = 1\nh_mul : ∀ (x y : M), f (x * y) ≤ f x * f y\ns : Finset ι\ng : ι → M\n⊢ Multiset.prod (Multiset.map (f ∘ fun i => g i) s.val) ≤ ∏ i in s, f (g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n ","nextTactic":"rfl","declUpToTactic":"/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.90_0.RJ9z80YJpu1cs9E","decl":"/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf g : ι → N\ns t : Finset ι\nh : ∀ i ∈ s, 1 ≤ f i\n⊢ 1 ≤ ∏ i in s, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by ","nextTactic":"rw [prod_const_one]","declUpToTactic":"@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.138_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf g : ι → N\ns t : Finset ι\nh : ∀ i ∈ s, f i ≤ 1\n⊢ ∏ i in s, 1 = 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by ","nextTactic":"rw [prod_const_one]","declUpToTactic":"@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.150_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf g : ι → N\ns t : Finset ι\nh : s ⊆ t\nhf : ∀ i ∈ t, i ∉ s → 1 ≤ f i\n⊢ ∏ i in s, f i ≤ ∏ i in t, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n ","nextTactic":"classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]","declUpToTactic":"@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.156_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf g : ι → N\ns t : Finset ι\nh : s ⊆ t\nhf : ∀ i ∈ t, i ∉ s → 1 ≤ f i\n⊢ ∏ i in s, f i ≤ ∏ i in t, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical ","nextTactic":"calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]","declUpToTactic":"@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.156_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf g : ι → N\ns t : Finset ι\nh : s ⊆ t\nhf : ∀ i ∈ t, i ∉ s → 1 ≤ f i\n⊢ ∀ i ∈ t \\ s, 1 ≤ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by ","nextTactic":"simpa only [mem_sdiff, and_imp]","declUpToTactic":"@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.156_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf g : ι → N\ns t : Finset ι\nh : s ⊆ t\nhf : ∀ i ∈ t, i ∉ s → 1 ≤ f i\n⊢ ∏ i in t \\ s ∪ s, f i = ∏ i in t, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by ","nextTactic":"rw [sdiff_union_of_subset h]","declUpToTactic":"@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.156_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf g : ι → N\ns t : Finset ι\n⊢ (∀ i ∈ s, 1 ≤ f i) → (∏ i in s, f i = 1 ↔ ∀ i ∈ s, f i = 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n ","nextTactic":"classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]","declUpToTactic":"@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.181_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf g : ι → N\ns t : Finset ι\n⊢ (∀ i ∈ s, 1 ≤ f i) → (∏ i in s, f i = 1 ↔ ∀ i ∈ s, f i = 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n ","nextTactic":"refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_","declUpToTactic":"@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.181_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf g : ι → N\ns t : Finset ι\n⊢ ∀ ⦃a : ι⦄ {s : Finset ι},\n a ∉ s →\n ((∀ i ∈ s, 1 ≤ f i) → (∏ i in s, f i = 1 ↔ ∀ i ∈ s, f i = 1)) →\n (∀ i ∈ insert a s, 1 ≤ f i) → (∏ i in insert a s, f i = 1 ↔ ∀ i ∈ insert a s, f i = 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n ","nextTactic":"intro a s ha ih H","declUpToTactic":"@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.181_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf g : ι → N\ns✝ t : Finset ι\na : ι\ns : Finset ι\nha : a ∉ s\nih : (∀ i ∈ s, 1 ≤ f i) → (∏ i in s, f i = 1 ↔ ∀ i ∈ s, f i = 1)\nH : ∀ i ∈ insert a s, 1 ≤ f i\n⊢ ∏ i in insert a s, f i = 1 ↔ ∀ i ∈ insert a s, f i = 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n ","nextTactic":"have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem","declUpToTactic":"@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.181_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf g : ι → N\ns✝ t : Finset ι\na : ι\ns : Finset ι\nha : a ∉ s\nih : (∀ i ∈ s, 1 ≤ f i) → (∏ i in s, f i = 1 ↔ ∀ i ∈ s, f i = 1)\nH : ∀ i ∈ insert a s, 1 ≤ f i\nthis : ∀ i ∈ s, 1 ≤ f i\n⊢ ∏ i in insert a s, f i = 1 ↔ ∀ i ∈ insert a s, f i = 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n ","nextTactic":"rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]","declUpToTactic":"@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.181_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf g : ι → N\ns t : Finset ι\ni j : ι\nhf : ∀ i ∈ s, 1 ≤ f i\nhi : i ∈ s\nhj : j ∈ s\nhne : i ≠ j\n⊢ i ∉ {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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by ","nextTactic":"simpa","declUpToTactic":"@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.211_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf g : ι → N\ns t : Finset ι\ni j : ι\nhf : ∀ i ∈ s, 1 ≤ f i\nhi : i ∈ s\nhj : j ∈ s\nhne : i ≠ j\n⊢ f i * f j = ∏ k in cons i {j} (_ : i ∉ {j}), f 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by ","nextTactic":"rw [prod_cons, prod_singleton]","declUpToTactic":"@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.211_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf g : ι → N\ns t : Finset ι\ni j : ι\nhf : ∀ i ∈ s, 1 ≤ f i\nhi : i ∈ s\nhj : j ∈ s\nhne : i ≠ j\n⊢ ∏ k in cons i {j} (_ : i ∉ {j}), f k ≤ ∏ k in s, f 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n ","nextTactic":"refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk","declUpToTactic":"@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.211_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf g : ι → N\ns t : Finset ι\ni j : ι\nhf : ∀ i ∈ s, 1 ≤ f i\nhi : i ∈ s\nhj : j ∈ s\nhne : i ≠ j\n⊢ cons i {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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n ","nextTactic":"simp [cons_subset, *]","declUpToTactic":"@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.211_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf✝ g : ι → N\ns✝ t s : Finset ι\nf : ι → N\nn : N\nh : ∀ x ∈ s, f x ≤ n\n⊢ Finset.prod s f ≤ n ^ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n ","nextTactic":"refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _","declUpToTactic":"@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.220_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card "} +{"state":"case refine'_1\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf✝ g : ι → N\ns✝ t s : Finset ι\nf : ι → N\nn : N\nh : ∀ x ∈ s, f x ≤ n\n⊢ ∀ x ∈ Multiset.map f s.val, x ≤ n","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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · ","nextTactic":"simpa using h","declUpToTactic":"@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.220_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : CommMonoid M\ninst✝ : OrderedCommMonoid N\nf✝ g : ι → N\ns✝ t s : Finset ι\nf : ι → N\nn : N\nh : ∀ x ∈ s, f x ≤ n\n⊢ n ^ Multiset.card (Multiset.map f s.val) ≤ n ^ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · ","nextTactic":"simp","declUpToTactic":"@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.220_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG✝ : Type u_6\nk : Type u_7\nR : Type u_8\nG : Type u_9\ninst✝ : LinearOrderedAddCommGroup G\nf : ι → G\ns : Finset ι\nhf : ∀ i ∈ s, 0 ≤ f i\n⊢ |∑ i in s, f i| = ∑ i in 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n ","nextTactic":"rw [abs_of_nonneg (Finset.sum_nonneg hf)]","declUpToTactic":"theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.271_0.RJ9z80YJpu1cs9E","decl":"theorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG✝ : Type u_6\nk : Type u_7\nR : Type u_8\nG : Type u_9\ninst✝ : LinearOrderedAddCommGroup G\nf : ι → G\ns : Finset ι\nhf : ∀ (i : ι), 0 ≤ f i\n⊢ |∑ i in s, f i| = ∑ i in 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x ��� p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n ","nextTactic":"rw [abs_of_nonneg (Finset.sum_nonneg' hf)]","declUpToTactic":"theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.276_0.RJ9z80YJpu1cs9E","decl":"theorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : DecidableEq β\nf : α → β\ns : Finset α\nt : Finset β\nHf : ∀ a ∈ s, f a ∈ t\nn : ℕ\nhn : ∀ a ∈ t, card (filter (fun x => f x = a) s) ≤ n\n⊢ ∑ _a in t, n = n * card 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ N���ᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by ","nextTactic":"simp [mul_comm]","declUpToTactic":"theorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.290_0.RJ9z80YJpu1cs9E","decl":"theorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : DecidableEq β\nf : α → β\ns : Finset α\nt : Finset β\nHf : ∀ a ∈ s, f a ∈ t\nn : ℕ\nhn : ∀ a ∈ t, n ≤ card (filter (fun x => f x = a) s)\n⊢ n * card t = ∑ _a in t, n","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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι �� Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by ","nextTactic":"simp [mul_comm]","declUpToTactic":"theorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.304_0.RJ9z80YJpu1cs9E","decl":"theorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : DecidableEq β\nf : α → β\ns : Finset α\nt : Finset β\nHf : ∀ a ∈ s, f a ∈ t\nn : ℕ\nhn : ∀ a ∈ t, n ≤ card (filter (fun x => f x = a) s)\n⊢ ��� a in t, card (filter (fun x => f x = a) s) = 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by ","nextTactic":"rw [← card_eq_sum_card_fiberwise Hf]","declUpToTactic":"theorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.304_0.RJ9z80YJpu1cs9E","decl":"theorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : DecidableEq α\ns : Finset α\nB : Finset (Finset α)\nn : ℕ\nh : ∀ a ∈ s, card (filter (fun x => a ∈ x) B) ≤ n\n⊢ ∑ t in B, card (s ∩ t) ≤ card s * n","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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n ","nextTactic":"refine' le_trans _ (s.sum_le_card_nsmul _ _ h)","declUpToTactic":"/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.324_0.RJ9z80YJpu1cs9E","decl":"/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : DecidableEq α\ns : Finset α\nB : Finset (Finset α)\nn : ℕ\nh : ∀ a ∈ s, card (filter (fun x => a ∈ x) B) ≤ n\n⊢ ∑ t in B, card (s ∩ t) ≤ ∑ x in s, card (filter (fun x_1 => x ∈ x_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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ��� f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n ","nextTactic":"simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]","declUpToTactic":"/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.324_0.RJ9z80YJpu1cs9E","decl":"/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : DecidableEq α\ns : Finset α\nB : Finset (Finset α)\nn : ℕ\nh : ∀ a ∈ s, card (filter (fun x => a ∈ x) B) ≤ n\n⊢ (∑ x in B, ∑ a in s, if a ∈ x then 1 else 0) ≤ ∑ x in s, ∑ a in B, if x ∈ a then 1 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n ","nextTactic":"exact sum_comm.le","declUpToTactic":"/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.324_0.RJ9z80YJpu1cs9E","decl":"/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : DecidableEq α\ns : Finset α\nB : Finset (Finset α)\nn : ℕ\ninst✝ : Fintype α\nh : ∀ (a : α), card (filter (fun x => a ∈ x) B) ≤ n\n⊢ ∑ s in B, card s = ∑ s in B, card (univ ∩ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by ","nextTactic":"simp_rw [univ_inter]","declUpToTactic":"/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.333_0.RJ9z80YJpu1cs9E","decl":"/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : DecidableEq α\ns : Finset α\nB : Finset (Finset α)\nn : ℕ\nh : ∀ a ∈ s, n ≤ card (filter (fun x => a ∈ x) B)\n⊢ card s * n ≤ ∑ t in 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n ","nextTactic":"apply (s.card_nsmul_le_sum _ _ h).trans","declUpToTactic":"/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.342_0.RJ9z80YJpu1cs9E","decl":"/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : DecidableEq α\ns : Finset α\nB : Finset (Finset α)\nn : ℕ\nh : ∀ a ∈ s, n ≤ card (filter (fun x => a ∈ x) B)\n⊢ ∑ x in s, card (filter (fun x_1 => x ∈ x_1) B) ≤ ∑ t in 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n ","nextTactic":"simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]","declUpToTactic":"/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.342_0.RJ9z80YJpu1cs9E","decl":"/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : DecidableEq α\ns : Finset α\nB : Finset (Finset α)\nn : ℕ\nh : ∀ a ∈ s, n ≤ card (filter (fun x => a ∈ x) B)\n⊢ (∑ x in s, ∑ a in B, if x ∈ a then 1 else 0) ≤ ∑ x in B, ∑ a in s, if a ∈ x then 1 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n ","nextTactic":"exact sum_comm.le","declUpToTactic":"/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.342_0.RJ9z80YJpu1cs9E","decl":"/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : DecidableEq α\ns : Finset α\nB : Finset (Finset α)\nn : ℕ\ninst✝ : Fintype α\nh : ∀ (a : α), n ≤ card (filter (fun x => a ∈ x) B)\n⊢ ∑ s in B, card (univ ∩ s) = ∑ s in 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ��� ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by ","nextTactic":"simp_rw [univ_inter]","declUpToTactic":"/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.351_0.RJ9z80YJpu1cs9E","decl":"/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : DecidableEq α\ns : Finset α\nB : Finset (Finset α)\nn : ℕ\ninst✝ : Fintype α\nh : ∀ (a : α), card (filter (fun x => a ∈ x) B) = n\n⊢ ∑ s in B, card s = Fintype.card α * n","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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n ","nextTactic":"simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]","declUpToTactic":"/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.367_0.RJ9z80YJpu1cs9E","decl":"/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : DecidableEq α\ns✝ : Finset α\nB : Finset (Finset α)\nn : ℕ\ns : Finset ι\nf : ι → Finset α\nhs : Set.PairwiseDisjoint (↑s) f\nhf : ∀ i ∈ s, Finset.Nonempty (f i)\n⊢ card s ≤ card (Finset.biUnion s f)","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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n ","nextTactic":"rw [card_biUnion hs]","declUpToTactic":"theorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.374_0.RJ9z80YJpu1cs9E","decl":"theorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : DecidableEq α\ns✝ : Finset α\nB : Finset (Finset α)\nn : ℕ\ns : Finset ι\nf : ι → Finset α\nhs : Set.PairwiseDisjoint (↑s) f\nhf : ∀ i ∈ s, Finset.Nonempty (f i)\n⊢ card s ≤ ∑ u in s, card (f u)","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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n ","nextTactic":"rw [card_eq_sum_ones]","declUpToTactic":"theorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.374_0.RJ9z80YJpu1cs9E","decl":"theorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : DecidableEq α\ns✝ : Finset α\nB : Finset (Finset α)\nn : ℕ\ns : Finset ι\nf : ι → Finset α\nhs : Set.PairwiseDisjoint (↑s) f\nhf : ∀ i ∈ s, Finset.Nonempty (f i)\n⊢ ∑ x in s, 1 ≤ ∑ u in s, card (f u)","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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n ","nextTactic":"exact sum_le_sum fun i hi ↦ (hf i hi).card_pos","declUpToTactic":"theorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.374_0.RJ9z80YJpu1cs9E","decl":"theorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : DecidableEq α\ns✝ : Finset α\nB : Finset (Finset α)\nn : ℕ\ns : Finset ι\nf : ι → Finset α\nhs : Set.PairwiseDisjoint (↑s) f\n⊢ card s ≤ card (Finset.biUnion s f) + card (filter (fun i => f i = ∅) 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n ","nextTactic":"rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]","declUpToTactic":"theorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.381_0.RJ9z80YJpu1cs9E","decl":"theorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : DecidableEq α\ns✝ : Finset α\nB : Finset (Finset α)\nn : ℕ\ns : Finset ι\nf : ι → Finset α\nhs : Set.PairwiseDisjoint (↑s) f\n⊢ card (filter (fun i => f i = ∅) s) + card (filter (fun a => ¬f a = ∅) s) ≤\n card (Finset.biUnion s f) + card (filter (fun i => f i = ∅) 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n ","nextTactic":"rw [add_comm]","declUpToTactic":"theorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.381_0.RJ9z80YJpu1cs9E","decl":"theorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : DecidableEq α\ns✝ : Finset α\nB : Finset (Finset α)\nn : ℕ\ns : Finset ι\nf : ι → Finset α\nhs : Set.PairwiseDisjoint (↑s) f\n⊢ card (filter (fun a => ¬f a = ∅) s) + card (filter (fun i => f i = ∅) s) ≤\n card (Finset.biUnion s f) + card (filter (fun i => f i = ∅) 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n ","nextTactic":"exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _","declUpToTactic":"theorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.381_0.RJ9z80YJpu1cs9E","decl":"theorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommMonoid M\nf : ι → M\ns t : Finset ι\nh : ∀ x ∈ s, f x ≠ 1 → x ∈ t\n⊢ ∏ x in s, f x ≤ ∏ x in t, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n ","nextTactic":"classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )","declUpToTactic":"@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.425_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommMonoid M\nf : ι → M\ns t : Finset ι\nh : ∀ x ∈ s, f x ≠ 1 → x ∈ t\n⊢ ∏ x in s, f x ≤ ∏ x in t, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical ","nextTactic":"calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )","declUpToTactic":"@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.425_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommMonoid M\nf : ι → M\ns t : Finset ι\nh : ∀ x ∈ s, f x ≠ 1 → x ∈ t\n⊢ ∏ x in s, f x = (∏ x in filter (fun x => f x = 1) s, f x) * ∏ x in filter (fun x => f x ≠ 1) 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n ","nextTactic":"rw [← prod_union]","declUpToTactic":"@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.425_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommMonoid M\nf : ι → M\ns t : Finset ι\nh : ∀ x ∈ s, f x ≠ 1 → x ∈ t\n⊢ ∏ x in s, f x = ∏ x in filter (fun x => f x = 1) s ∪ filter (fun x => f x ≠ 1) s, f x\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommMonoid M\nf : ι → M\ns t : Finset ι\nh : ∀ x ∈ s, f x ≠ 1 → x ∈ t\n⊢ Disjoint (filter (fun x => f x = 1) s) (filter (fun x => f x ≠ 1) 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n ","nextTactic":"rw [filter_union_filter_neg_eq]","declUpToTactic":"@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.425_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommMonoid M\nf : ι → M\ns t : Finset ι\nh : ∀ x ∈ s, f x ≠ 1 → x ∈ t\n⊢ Disjoint (filter (fun x => f x = 1) s) (filter (fun x => f x ≠ 1) 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n ","nextTactic":"exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h","declUpToTactic":"@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.425_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommMonoid M\nf : ι → M\ns t : Finset ι\nh : ∀ x ∈ s, f x ≠ 1 → x ∈ t\n⊢ ∀ i ∈ filter (fun x => f x = 1) s, f i ≤ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by ","nextTactic":"simp only [mem_filter, and_imp]","declUpToTactic":"@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.425_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommMonoid M\nf : ι → M\ns t : Finset ι\nh : ∀ x ∈ s, f x ≠ 1 → x ∈ t\n⊢ ∀ i ∈ s, f i = 1 → f i ≤ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; ","nextTactic":"exact fun _ _ ↦ le_of_eq","declUpToTactic":"@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.425_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommMonoid M\nf : ι → M\ns t : Finset ι\nh : ∀ x ∈ s, f x ≠ 1 → x ∈ t\n⊢ filter (fun x => f x ≠ 1) 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by ","nextTactic":"simpa only [subset_iff, mem_filter, and_imp]","declUpToTactic":"@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.425_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\nhs : Finset.Nonempty s\nhlt : ∀ i ∈ s, f i < g i\n⊢ s.val ≠ ∅","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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by ","nextTactic":"aesop","declUpToTactic":"@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.454_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\nh : s ⊆ t\ni : ι\nht : i ∈ t\nhs : i ∉ s\nhlt : 1 < f i\nhle : ∀ j ∈ t, j ∉ s → 1 ≤ f j\n⊢ ∏ j in s, f j < ∏ j in t, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n ","nextTactic":"classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2","declUpToTactic":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.481_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\nh : s ⊆ t\ni : ι\nht : i ∈ t\nhs : i ∉ s\nhlt : 1 < f i\nhle : ∀ j ∈ t, j ∉ s → 1 ≤ f j\n⊢ ∏ j in s, f j < ∏ j in t, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical ","nextTactic":"calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2","declUpToTactic":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.481_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\nh : s ⊆ t\ni : ι\nht : i ∈ t\nhs : i ∉ s\nhlt : 1 < f i\nhle : ∀ j ∈ t, j ∉ s → 1 ≤ f j\n⊢ ∏ j in s, f j < ∏ j in insert i 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ �� hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n ","nextTactic":"rw [prod_insert hs]","declUpToTactic":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.481_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\nh : s ⊆ t\ni : ι\nht : i ∈ t\nhs : i ∉ s\nhlt : 1 < f i\nhle : ∀ j ∈ t, j ∉ s → 1 ≤ f j\n⊢ ∏ j in s, f j < f i * ∏ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `���` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n ","nextTactic":"exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt","declUpToTactic":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.481_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\nh : s ⊆ t\ni : ι\nht : i ∈ t\nhs : i ∉ s\nhlt : 1 < f i\nhle : ∀ j ∈ t, j ∉ s → 1 ≤ f j\n⊢ ∏ j in insert i s, f j ≤ ∏ j in t, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n ","nextTactic":"apply prod_le_prod_of_subset_of_one_le'","declUpToTactic":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.481_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j "} +{"state":"case h\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\nh : s ⊆ t\ni : ι\nht : i ∈ t\nhs : i ∉ s\nhlt : 1 < f i\nhle : ∀ j ∈ t, j ∉ s → 1 ≤ f j\n⊢ insert i 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι ��� N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ��� s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · ","nextTactic":"simp [Finset.insert_subset_iff, h, ht]","declUpToTactic":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.481_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j "} +{"state":"case hf\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\nh : s ⊆ t\ni : ι\nht : i ∈ t\nhs : i ∉ s\nhlt : 1 < f i\nhle : ∀ j ∈ t, j ∉ s → 1 ≤ f j\n⊢ ∀ i_1 ∈ t, i_1 ∉ insert i s → 1 ≤ f i_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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · ","nextTactic":"intro x hx h'x","declUpToTactic":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.481_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j "} +{"state":"case hf\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\nh : s ⊆ t\ni : ι\nht : i ∈ t\nhs : i ∉ s\nhlt : 1 < f i\nhle : ∀ j ∈ t, j ∉ s → 1 ≤ f j\nx : ι\nhx : x ∈ t\nh'x : x ∉ insert i s\n⊢ 1 ≤ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = �� k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n ","nextTactic":"simp only [mem_insert, not_or] at h'x","declUpToTactic":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.481_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j "} +{"state":"case hf\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\nh : s ⊆ t\ni : ι\nht : i ∈ t\nhs : i ∉ s\nhlt : 1 < f i\nhle : ∀ j ∈ t, j ∉ s → 1 ≤ f j\nx : ι\nhx : x ∈ t\nh'x : ¬x = i ∧ x ∉ s\n⊢ 1 ≤ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n ","nextTactic":"exact hle x hx h'x.2","declUpToTactic":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.481_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\ni j : ι\nhij : j ≠ i\nhi : i ∈ s\nhj : j ∈ s\nhlt : 1 < f j\nhle : ∀ k ∈ s, k ≠ i → 1 ≤ f k\n⊢ f i = ∏ k in {i}, f 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) �� f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by ","nextTactic":"rw [prod_singleton]","declUpToTactic":"@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.497_0.RJ9z80YJpu1cs9E","decl":"@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\nh : ∀ i ∈ s, 1 < f i\nhs : Finset.Nonempty s\n⊢ 1 ≤ ∏ i in s, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by ","nextTactic":"rw [prod_const_one]","declUpToTactic":"@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.508_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\nh : ∀ i ∈ s, f i < 1\nhs : Finset.Nonempty s\n⊢ ∏ i in s, 1 ≤ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by ","nextTactic":"rw [prod_const_one]","declUpToTactic":"@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.514_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf✝ g✝ : ι → M\ns t : Finset ι\nf g : ι → M\nh : ∀ i ∈ s, f i ≤ g i\n⊢ ∏ i in s, f i = ∏ i in s, g i ↔ ∀ i ∈ s, f i = g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x �� ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n ","nextTactic":"classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)","declUpToTactic":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.532_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf✝ g✝ : ι → M\ns t : Finset ι\nf g : ι → M\nh : ∀ i ∈ s, f i ≤ g i\n⊢ ∏ i in s, f i = ∏ i in s, g i ↔ ∀ i ∈ s, f i = g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n ","nextTactic":"revert h","declUpToTactic":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.532_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf✝ g✝ : ι → M\ns t : Finset ι\nf g : ι → M\n⊢ (∀ i ∈ s, f i ≤ g i) → (∏ i in s, f i = ∏ i in s, g i ↔ ∀ i ∈ s, f i = g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n ","nextTactic":"refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_","declUpToTactic":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.532_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf✝ g✝ : ι → M\ns✝ t : Finset ι\nf g : ι → M\na : ι\ns : Finset ι\nha : a ∉ s\nih : (∀ i ∈ s, f i ≤ g i) → (∏ i in s, f i = ∏ i in s, g i ↔ ∀ i ∈ s, f i = g i)\nH : ∀ i ∈ insert a s, f i ≤ g i\n⊢ ∏ i in insert a s, f i = ∏ i in insert a s, g i ↔ ∀ i ∈ insert a s, f i = g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : �� → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n ","nextTactic":"specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem","declUpToTactic":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.532_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf✝ g✝ : ι → M\ns✝ t : Finset ι\nf g : ι → M\na : ι\ns : Finset ι\nha : a ∉ s\nH : ∀ i ∈ insert a s, f i ≤ g i\nih : ∏ i in s, f i = ∏ i in s, g i ↔ ∀ i ∈ s, f i = g i\n⊢ ∏ i in insert a s, f i = ∏ i in insert a s, g i ↔ ∀ i ∈ insert a s, f i = g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n ","nextTactic":"rw [Finset.prod_insert ha]","declUpToTactic":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.532_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf✝ g✝ : ι → M\ns✝ t : Finset ι\nf g : ι → M\na : ι\ns : Finset ι\nha : a ∉ s\nH : ∀ i ∈ insert a s, f i ≤ g i\nih : ∏ i in s, f i = ∏ i in s, g i ↔ ∀ i ∈ s, f i = g i\n⊢ f a * ∏ x in s, f x = ∏ i in insert a s, g i ↔ ∀ i ∈ insert a s, f i = g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ��� g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ��}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n ","nextTactic":"rw [Finset.prod_insert ha]","declUpToTactic":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.532_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf✝ g✝ : ι → M\ns✝ t : Finset ι\nf g : ι → M\na : ι\ns : Finset ι\nha : a ∉ s\nH : ∀ i ∈ insert a s, f i ≤ g i\nih : ∏ i in s, f i = ∏ i in s, g i ↔ ∀ i ∈ s, f i = g i\n⊢ f a * ∏ x in s, f x = g a * ∏ x in s, g x ↔ ∀ i ∈ insert a s, f i = g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n ","nextTactic":"rw [Finset.forall_mem_insert]","declUpToTactic":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.532_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf✝ g✝ : ι → M\ns✝ t : Finset ι\nf g : ι → M\na : ι\ns : Finset ι\nha : a ∉ s\nH : ∀ i ∈ insert a s, f i ≤ g i\nih : ∏ i in s, f i = ∏ i in s, g i ↔ ∀ i ∈ s, f i = g i\n⊢ f a * ∏ x in s, f x = g a * ∏ x in s, g x ↔ f a = g a ∧ ∀ x ∈ s, f x = g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n ","nextTactic":"rw [← ih]","declUpToTactic":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.532_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCancelCommMonoid M\nf✝ g✝ : ι → M\ns✝ t : Finset ι\nf g : ι → M\na : ι\ns : Finset ι\nha : a ∉ s\nH : ∀ i ∈ insert a s, f i ≤ g i\nih : ∏ i in s, f i = ∏ i in s, g i ↔ ∀ i ∈ s, f i = g i\n⊢ f a * ∏ x in s, f x = g a * ∏ x in s, g x ↔ f a = g a ∧ ∏ i in s, f i = ∏ i in s, g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n ","nextTactic":"exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)","declUpToTactic":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.532_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\ninst✝ : DecidableEq ι\n⊢ ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n ","nextTactic":"rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter]","declUpToTactic":"@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.552_0.RJ9z80YJpu1cs9E","decl":"@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\ninst✝ : DecidableEq ι\n⊢ Disjoint (t \\ s) (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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n ","nextTactic":"simpa only [inter_comm] using disjoint_sdiff_inter t s","declUpToTactic":"@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.552_0.RJ9z80YJpu1cs9E","decl":"@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\ninst✝ : DecidableEq ι\n⊢ ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n ","nextTactic":"rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter]","declUpToTactic":"@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.558_0.RJ9z80YJpu1cs9E","decl":"@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : OrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\ninst✝ : DecidableEq ι\n⊢ Disjoint (t \\ s) (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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card �� n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n ","nextTactic":"simpa only [inter_comm] using disjoint_sdiff_inter t s","declUpToTactic":"@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.558_0.RJ9z80YJpu1cs9E","decl":"@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : LinearOrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\nHlt : ∏ i in s, f i < ∏ i in s, g i\n⊢ ∃ i ∈ s, f i < g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n ","nextTactic":"contrapose! Hlt with Hle","declUpToTactic":"@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.570_0.RJ9z80YJpu1cs9E","decl":"@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : LinearOrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\nHle : ∀ i ∈ s, g i ≤ f i\n⊢ ∏ i in s, g i ≤ ∏ i in 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n ","nextTactic":"exact prod_le_prod' Hle","declUpToTactic":"@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.570_0.RJ9z80YJpu1cs9E","decl":"@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : LinearOrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\nhs : Finset.Nonempty s\nHle : ∏ i in s, f i ≤ ∏ i in s, g i\n⊢ ∃ i ∈ s, f i ≤ g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n ","nextTactic":"contrapose! Hle with Hlt","declUpToTactic":"@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.577_0.RJ9z80YJpu1cs9E","decl":"@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ��� g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : LinearOrderedCancelCommMonoid M\nf g : ι → M\ns t : Finset ι\nhs : Finset.Nonempty s\nHlt : ∀ i ∈ s, g i < f i\n⊢ ∏ i in s, g i < ∏ i in 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n ","nextTactic":"exact prod_lt_prod_of_nonempty' hs Hlt","declUpToTactic":"@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.577_0.RJ9z80YJpu1cs9E","decl":"@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : LinearOrderedCancelCommMonoid M\nf✝ g : ι → M\ns t : Finset ι\nf : ι → M\nh₁ : ∏ i in s, f i = 1\nh₂ : ∃ i ∈ s, f i ≠ 1\n⊢ ∃ i ∈ s, 1 < 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n ","nextTactic":"contrapose! h₁","declUpToTactic":"@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.585_0.RJ9z80YJpu1cs9E","decl":"@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : LinearOrderedCancelCommMonoid M\nf✝ g : ι → M\ns t : Finset ι\nf : ι → M\nh₂ : ∃ i ∈ s, f i ≠ 1\nh₁ : ∀ i ∈ s, f i ≤ 1\n⊢ ∏ i in s, f i ≠ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ��� t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n ","nextTactic":"obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂","declUpToTactic":"@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i �� s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.585_0.RJ9z80YJpu1cs9E","decl":"@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i "} +{"state":"case intro.intro\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : LinearOrderedCancelCommMonoid M\nf✝ g : ι → M\ns t : Finset ι\nf : ι → M\nh₁ : ∀ i ∈ s, f i ≤ 1\ni : ι\nm : i ∈ s\ni_ne : f i ≠ 1\n⊢ ∏ i in s, f i ≠ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n ","nextTactic":"apply ne_of_lt","declUpToTactic":"@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.585_0.RJ9z80YJpu1cs9E","decl":"@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i "} +{"state":"case intro.intro.h\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : LinearOrderedCancelCommMonoid M\nf✝ g : ι → M\ns t : Finset ι\nf : ι → M\nh₁ : ∀ i ∈ s, f i ≤ 1\ni : ι\nm : i ∈ s\ni_ne : f i ≠ 1\n⊢ ∏ i in s, f i < 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n ","nextTactic":"calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one","declUpToTactic":"@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.585_0.RJ9z80YJpu1cs9E","decl":"@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf g : ι → R\ns t : Finset ι\nh0 : ∀ i ∈ s, 0 ≤ f i\nh1 : ∀ i ∈ s, f i ≤ g i\n⊢ ∏ i in s, f i ≤ ∏ i in s, g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n ","nextTactic":"induction' s using Finset.induction with a s has ih h","declUpToTactic":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.610_0.RJ9z80YJpu1cs9E","decl":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i "} +{"state":"case empty\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf g : ι → R\ns t : Finset ι\nh0 : ∀ i ∈ ∅, 0 ≤ f i\nh1 : ∀ i ∈ ∅, f i ≤ g i\n⊢ ∏ i in ∅, f i ≤ ∏ i in ∅, g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · ","nextTactic":"simp","declUpToTactic":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.610_0.RJ9z80YJpu1cs9E","decl":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i "} +{"state":"case insert\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf g : ι → R\ns✝ t : Finset ι\na : ι\ns : Finset ι\nhas : a ∉ s\nih : (∀ i ∈ s, 0 ≤ f i) → (∀ i ∈ s, f i ≤ g i) → ∏ i in s, f i ≤ ∏ i in s, g i\nh0 : ∀ i ∈ insert a s, 0 ≤ f i\nh1 : ∀ i ∈ insert a s, f i ≤ g i\n⊢ ∏ i in insert a s, f i ≤ ∏ i in insert a s, g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ��� i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · ","nextTactic":"simp only [prod_insert has]","declUpToTactic":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.610_0.RJ9z80YJpu1cs9E","decl":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i "} +{"state":"case insert\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf g : ι → R\ns✝ t : Finset ι\na : ι\ns : Finset ι\nhas : a ∉ s\nih : (∀ i ∈ s, 0 ≤ f i) → (∀ i ∈ s, f i ≤ g i) → ∏ i in s, f i ≤ ∏ i in s, g i\nh0 : ∀ i ∈ insert a s, 0 ≤ f i\nh1 : ∀ i ∈ insert a s, f i ≤ g i\n⊢ f a * ∏ i in s, f i ≤ g a * ∏ i in s, g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n ","nextTactic":"apply mul_le_mul","declUpToTactic":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.610_0.RJ9z80YJpu1cs9E","decl":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i "} +{"state":"case insert.h₁\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf g : ι → R\ns✝ t : Finset ι\na : ι\ns : Finset ι\nhas : a ∉ s\nih : (∀ i ∈ s, 0 ≤ f i) → (∀ i ∈ s, f i ≤ g i) → ∏ i in s, f i ≤ �� i in s, g i\nh0 : ∀ i ∈ insert a s, 0 ≤ f i\nh1 : ∀ i ∈ insert a s, f i ≤ g i\n⊢ f a ≤ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · ","nextTactic":"exact h1 a (mem_insert_self a s)","declUpToTactic":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.610_0.RJ9z80YJpu1cs9E","decl":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i "} +{"state":"case insert.h₂\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf g : ι → R\ns✝ t : Finset ι\na : ι\ns : Finset ι\nhas : a ∉ s\nih : (∀ i ∈ s, 0 ≤ f i) → (∀ i ∈ s, f i ≤ g i) → ∏ i in s, f i ≤ ∏ i in s, g i\nh0 : ∀ i ∈ insert a s, 0 ≤ f i\nh1 : ∀ i ∈ insert a s, f i ≤ g i\n⊢ ∏ i in s, f i ≤ ∏ i in s, g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · ","nextTactic":"refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_)","declUpToTactic":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.610_0.RJ9z80YJpu1cs9E","decl":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i "} +{"state":"case insert.h₂.refine_1\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf g : ι → R\ns✝ t : Finset ι\na : ι\ns : Finset ι\nhas : a ∉ s\nih : (∀ i ∈ s, 0 ≤ f i) → (∀ i ∈ s, f i ≤ g i) → ∏ i in s, f i ≤ ∏ i in s, g i\nh0 : ∀ i ∈ insert a s, 0 ≤ f i\nh1 : ∀ i ∈ insert a s, f i ≤ g i\nx : ι\nH : x ∈ s\n⊢ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> ","nextTactic":"exact mem_insert_of_mem H","declUpToTactic":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.610_0.RJ9z80YJpu1cs9E","decl":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i "} +{"state":"case insert.h₂.refine_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf g : ι → R\ns✝ t : Finset ι\na : ι\ns : Finset ι\nhas : a ∉ s\nih : (∀ i ∈ s, 0 ≤ f i) → (∀ i ∈ s, f i ≤ g i) → ∏ i in s, f i ≤ ∏ i in s, g i\nh0 : ∀ i ∈ insert a s, 0 ≤ f i\nh1 : ∀ i ∈ insert a s, f i ≤ g i\nx : ι\nH : x ∈ s\n⊢ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ��� s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> ","nextTactic":"exact mem_insert_of_mem H","declUpToTactic":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.610_0.RJ9z80YJpu1cs9E","decl":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i "} +{"state":"case insert.c0\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf g : ι → R\ns✝ t : Finset ι\na : ι\ns : Finset ι\nhas : a ∉ s\nih : (∀ i ∈ s, 0 ≤ f i) → (∀ i ∈ s, f i ≤ g i) → ∏ i in s, f i ≤ ∏ i in s, g i\nh0 : ∀ i ∈ insert a s, 0 ≤ f i\nh1 : ∀ i ∈ insert a s, f i ≤ g i\n⊢ 0 ≤ ∏ i in 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · ","nextTactic":"apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)","declUpToTactic":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.610_0.RJ9z80YJpu1cs9E","decl":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i "} +{"state":"case insert.b0\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf g : ι → R\ns✝ t : Finset ι\na : ι\ns : Finset ι\nhas : a ∉ s\nih : (∀ i ∈ s, 0 ≤ f i) → (∀ i ∈ s, f i ≤ g i) → ∏ i in s, f i ≤ ∏ i in s, g i\nh0 : ∀ i ∈ insert a s, 0 ≤ f i\nh1 : ∀ i ∈ insert a s, f i ≤ g i\n⊢ 0 ≤ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ �� i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · ","nextTactic":"apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))","declUpToTactic":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.610_0.RJ9z80YJpu1cs9E","decl":"/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf g : ι → R\ns t : Finset ι\nh0 : ∀ i ∈ s, 0 ≤ f i\nh1 : ∀ i ∈ s, f i ≤ 1\n⊢ ∏ i in s, f i ≤ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n ","nextTactic":"convert ← prod_le_prod h0 h1","declUpToTactic":"/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.635_0.RJ9z80YJpu1cs9E","decl":"/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 "} +{"state":"case h.e'_4\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf g : ι → R\ns t : Finset ι\nh0 : ∀ i ∈ s, 0 ≤ f i\nh1 : ∀ i ∈ s, f i ≤ 1\n⊢ ∏ i in s, 1 = 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ��� ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n ","nextTactic":"exact Finset.prod_const_one","declUpToTactic":"/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.635_0.RJ9z80YJpu1cs9E","decl":"/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ ∏ i in s, g i + ∏ i in s, h i ≤ ∏ i in 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n ","nextTactic":"simp_rw [prod_eq_mul_prod_diff_singleton hi]","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ g i * ∏ i in s \\ {i}, g i + h i * ∏ i in s \\ {i}, h i ≤ f i * ∏ i in s \\ {i}, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n ","nextTactic":"refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ g i * ∏ i in s \\ {i}, g i + h i * ∏ i in s \\ {i}, h i ≤ (g i + h i) * ∏ i in s \\ {i}, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · ","nextTactic":"rw [right_distrib]","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ g i * ∏ i in s \\ {i}, g i + h i * ∏ i in s \\ {i}, h i ≤ g i * ∏ i in s \\ {i}, f i + h i * ∏ i in s \\ {i}, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n ","nextTactic":"refine add_le_add ?_ ?_","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1.refine_1\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ g i * ∏ i in s \\ {i}, g i ≤ g i * ∏ i in s \\ {i}, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ��� H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · ","nextTactic":"refine mul_le_mul_of_nonneg_left ?_ ?_","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1.refine_1.refine_1\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ ∏ i in s \\ {i}, g i ≤ ∏ i in s \\ {i}, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · ","nextTactic":"refine prod_le_prod ?_ ?_","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1.refine_1.refine_1.refine_1\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ ∀ i_1 ∈ s \\ {i}, 0 ≤ g i_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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> ","nextTactic":"simp (config := { contextual := true }) [*]","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1.refine_1.refine_1.refine_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ ∀ i_1 ∈ s \\ {i}, g i_1 ≤ f i_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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> ","nextTactic":"simp (config := { contextual := true }) [*]","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1.refine_1.refine_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ 0 ≤ g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · ","nextTactic":"try apply_assumption","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1.refine_1.refine_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ 0 ≤ g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ��i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try ","nextTactic":"apply_assumption","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1.refine_1.refine_2.a\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ i ∈ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n ","nextTactic":"try assumption","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1.refine_1.refine_2.a\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ i ∈ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq ��]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try ","nextTactic":"assumption","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1.refine_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ h i * ∏ i in s \\ {i}, h i ≤ h i * ∏ i in s \\ {i}, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · ","nextTactic":"refine mul_le_mul_of_nonneg_left ?_ ?_","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1.refine_2.refine_1\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ ∏ i in s \\ {i}, h i ≤ ∏ i in s \\ {i}, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α ��� β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · ","nextTactic":"refine prod_le_prod ?_ ?_","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1.refine_2.refine_1.refine_1\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ ∀ i_1 ∈ s \\ {i}, 0 ≤ h i_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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> ","nextTactic":"simp (config := { contextual := true }) [*]","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1.refine_2.refine_1.refine_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ ∀ i_1 ∈ s \\ {i}, h i_1 ≤ f i_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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> ","nextTactic":"simp (config := { contextual := true }) [*]","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1.refine_2.refine_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ 0 ≤ h 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · ","nextTactic":"try apply_assumption","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1.refine_2.refine_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ 0 ≤ h 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try ","nextTactic":"apply_assumption","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1.refine_2.refine_2.a\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ i ∈ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ��� t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n ","nextTactic":"try assumption","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_1.refine_2.refine_2.a\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ i ∈ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a �� ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try ","nextTactic":"assumption","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ 0 ≤ ∏ i in s \\ {i}, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · ","nextTactic":"apply prod_nonneg","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_2.h0\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ ∀ i_1 ∈ s \\ {i}, 0 ≤ f i_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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n ","nextTactic":"simp only [and_imp, mem_sdiff, mem_singleton]","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_2.h0\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\n⊢ ∀ i_1 ∈ s, ¬i_1 = i → 0 ≤ f i_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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n ","nextTactic":"intro j h1j h2j","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ��� j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case refine_2.h0\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : OrderedCommSemiring R\nf✝ g✝ : ι → R\ns t : Finset ι\ni : ι\nf g h : ι → R\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\nhg : ∀ i ∈ s, 0 ≤ g i\nhh : ∀ i ∈ s, 0 ≤ h i\nj : ι\nh1j : j ∈ s\nh2j : ¬j = i\n⊢ 0 ≤ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n ","nextTactic":"exact le_trans (hg j h1j) (hgf j h1j h2j)","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.642_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : StrictOrderedCommSemiring R\nf g : ι → R\ns : Finset ι\nhf : ∀ i ∈ s, 0 < f i\nhfg : ∀ i ∈ s, f i ≤ g i\nhlt : ∃ i ∈ s, f i < g i\n⊢ ∏ i in s, f i < ∏ i in s, g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n ","nextTactic":"classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt","declUpToTactic":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.673_0.RJ9z80YJpu1cs9E","decl":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : StrictOrderedCommSemiring R\nf g : ι → R\ns : Finset ι\nhf : ∀ i ∈ s, 0 < f i\nhfg : ∀ i ∈ s, f i ≤ g i\nhlt : ∃ i ∈ s, f i < g i\n⊢ ∏ i in s, f i < ∏ i in s, g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n ","nextTactic":"obtain ⟨i, hi, hilt⟩ := hlt","declUpToTactic":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.673_0.RJ9z80YJpu1cs9E","decl":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i "} +{"state":"case intro.intro\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : StrictOrderedCommSemiring R\nf g : ι → R\ns : Finset ι\nhf : ∀ i ∈ s, 0 < f i\nhfg : ∀ i ∈ s, f i ≤ g i\ni : ι\nhi : i ∈ s\nhilt : f i < g i\n⊢ ∏ i in s, f i < ∏ i in s, g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n ","nextTactic":"rw [← insert_erase hi]","declUpToTactic":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.673_0.RJ9z80YJpu1cs9E","decl":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i "} +{"state":"case intro.intro\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : StrictOrderedCommSemiring R\nf g : ι → R\ns : Finset ι\nhf : ∀ i ∈ s, 0 < f i\nhfg : ∀ i ∈ s, f i ≤ g i\ni : ι\nhi : i ∈ s\nhilt : f i < g i\n⊢ ∏ i in insert i (erase s i), f i < ∏ i in insert i (erase s i), g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n ","nextTactic":"rw [prod_insert (not_mem_erase _ _)]","declUpToTactic":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.673_0.RJ9z80YJpu1cs9E","decl":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i "} +{"state":"case intro.intro\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : StrictOrderedCommSemiring R\nf g : ι → R\ns : Finset ι\nhf : ∀ i ∈ s, 0 < f i\nhfg : ∀ i ∈ s, f i ≤ g i\ni : ι\nhi : i ∈ s\nhilt : f i < g i\n⊢ f i * ∏ x in erase s i, f x < ∏ i in insert i (erase s i), g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n ","nextTactic":"rw [prod_insert (not_mem_erase _ _)]","declUpToTactic":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.673_0.RJ9z80YJpu1cs9E","decl":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i "} +{"state":"case intro.intro\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : StrictOrderedCommSemiring R\nf g : ι → R\ns : Finset ι\nhf : ∀ i ∈ s, 0 < f i\nhfg : ∀ i ∈ s, f i ≤ g i\ni : ι\nhi : i ∈ s\nhilt : f i < g i\n⊢ f i * ∏ x in erase s i, f x < g i * ∏ x in erase s i, g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n ","nextTactic":"apply mul_lt_mul hilt","declUpToTactic":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.673_0.RJ9z80YJpu1cs9E","decl":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i "} +{"state":"case intro.intro.hbd\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : StrictOrderedCommSemiring R\nf g : ι → R\ns : Finset ι\nhf : ∀ i ∈ s, 0 < f i\nhfg : ∀ i ∈ s, f i ≤ g i\ni : ι\nhi : i ∈ s\nhilt : f i < g i\n⊢ ∏ x in erase s i, f x ≤ ∏ x in erase s i, g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i �� f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · ","nextTactic":"exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)","declUpToTactic":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.673_0.RJ9z80YJpu1cs9E","decl":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i "} +{"state":"case intro.intro.hb\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : StrictOrderedCommSemiring R\nf g : ι → R\ns : Finset ι\nhf : ∀ i ∈ s, 0 < f i\nhfg : ∀ i ∈ s, f i ≤ g i\ni : ι\nhi : i ∈ s\nhilt : f i < g i\n⊢ 0 < ∏ x in erase s i, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · ","nextTactic":"exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)","declUpToTactic":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.673_0.RJ9z80YJpu1cs9E","decl":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i "} +{"state":"case intro.intro.hc\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : StrictOrderedCommSemiring R\nf g : ι → R\ns : Finset ι\nhf : ∀ i ∈ s, 0 < f i\nhfg : ∀ i ∈ s, f i ≤ g i\ni : ι\nhi : i ∈ s\nhilt : f i < g i\n⊢ 0 ≤ g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ��� ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · ","nextTactic":"exact le_of_lt <| (hf i hi).trans hilt","declUpToTactic":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.673_0.RJ9z80YJpu1cs9E","decl":"theorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : StrictOrderedCommSemiring R\nf g : ι → R\ns : Finset ι\nhf : ∀ i ∈ s, 0 < f i\nhfg : ∀ i ∈ s, f i < g i\nh_ne : Finset.Nonempty s\n⊢ ∏ i in s, f i < ∏ i in s, g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ��� ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n ","nextTactic":"apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)","declUpToTactic":"theorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.687_0.RJ9z80YJpu1cs9E","decl":"theorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : StrictOrderedCommSemiring R\nf g : ι → R\ns : Finset ι\nhf : ∀ i ∈ s, 0 < f i\nhfg : ∀ i ∈ s, f i < g i\nh_ne : Finset.Nonempty s\n⊢ ∃ i ∈ s, f i < g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (�� x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n ","nextTactic":"obtain ⟨i, hi⟩ := h_ne","declUpToTactic":"theorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.687_0.RJ9z80YJpu1cs9E","decl":"theorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i "} +{"state":"case intro\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : StrictOrderedCommSemiring R\nf g : ι → R\ns : Finset ι\nhf : ∀ i ∈ s, 0 < f i\nhfg : ∀ i ∈ s, f i < g i\ni : ι\nhi : i ∈ s\n⊢ ∃ i ∈ s, f i < g 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n ","nextTactic":"exact ⟨i, hi, hfg i hi⟩","declUpToTactic":"theorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.687_0.RJ9z80YJpu1cs9E","decl":"theorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\n⊢ ∏ i in s, g i + ∏ i in s, h i ≤ ∏ i in 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n ","nextTactic":"classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n assumption","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\n⊢ ∏ i in s, g i + ∏ i in s, h i ≤ ∏ i in 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i �� f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n ","nextTactic":"simp_rw [prod_eq_mul_prod_diff_singleton hi]","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\n⊢ g i * ∏ i in s \\ {i}, g i + h i * ∏ i in s \\ {i}, h i ≤ f i * ∏ i in s \\ {i}, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n ","nextTactic":"refine' le_trans _ (mul_le_mul_right' h2i _)","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\n⊢ g i * ∏ i in s \\ {i}, g i + h i * ∏ i in s \\ {i}, h i ≤ (g i + h i) * ∏ i in s \\ {i}, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ��)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n ","nextTactic":"rw [right_distrib]","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\n⊢ g i * ∏ i in s \\ {i}, g i + h i * ∏ i in s \\ {i}, h i ≤ g i * ∏ i in s \\ {i}, f i + h i * ∏ i in s \\ {i}, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i �� s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n ","nextTactic":"apply add_le_add","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case h₁\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\n⊢ g i * ∏ i in s \\ {i}, g i ≤ g i * ∏ i in s \\ {i}, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> ","nextTactic":"apply mul_le_mul_left'","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case h₂\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\n⊢ h i * ∏ i in s \\ {i}, h i ≤ h i * ∏ i in s \\ {i}, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> ","nextTactic":"apply mul_le_mul_left'","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case h₁.bc\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\n⊢ ∏ i in s \\ {i}, g i ≤ ∏ i in s \\ {i}, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha �� (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> ","nextTactic":"apply prod_le_prod'","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case h₂.bc\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\n⊢ ∏ i in s \\ {i}, h i ≤ ∏ i in s \\ {i}, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> ","nextTactic":"apply prod_le_prod'","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case h₁.bc.h\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\n⊢ ∀ i_1 ∈ s \\ {i}, g i_1 ≤ f i_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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n ","nextTactic":"simp only [and_imp, mem_sdiff, mem_singleton]","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case h₂.bc.h\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\n⊢ ∀ i_1 ∈ s \\ {i}, h i_1 ≤ f i_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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n ","nextTactic":"simp only [and_imp, mem_sdiff, mem_singleton]","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case h₁.bc.h\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\n⊢ ∀ i_1 ∈ s, ¬i_1 = i → g i_1 ≤ f i_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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n ","nextTactic":"intros","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case h₂.bc.h\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\n⊢ ∀ i_1 ∈ s, ¬i_1 = i → h i_1 ≤ f i_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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a �� s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n ","nextTactic":"intros","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case h₁.bc.h\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\ni✝ : ι\na✝¹ : i✝ ∈ s\na✝ : ¬i✝ = i\n⊢ g i✝ ≤ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n ","nextTactic":"apply_assumption","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ �� i in s, f i "} +{"state":"case h₂.bc.h\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\ni✝ : ι\na✝¹ : i✝ ∈ s\na✝ : ¬i✝ = i\n⊢ h i✝ ≤ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : �� → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n ","nextTactic":"apply_assumption","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case h₁.bc.h.a\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\ni✝ : ι\na✝¹ : i✝ ∈ s\na✝ : ¬i✝ = i\n⊢ i✝ ∈ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n ","nextTactic":"assumption","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case h₁.bc.h.a\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\ni✝ : ι\na✝¹ : i✝ ∈ s\na✝ : ¬i✝ = i\n⊢ i✝ ≠ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n ","nextTactic":"assumption","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case h₂.bc.h.a\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\ni✝ : ι\na✝¹ : i✝ ∈ s\na✝ : ¬i✝ = i\n⊢ i✝ ∈ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n ","nextTactic":"assumption","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"case h₂.bc.h.a\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : CanonicallyOrderedCommSemiring R\nf g h : ι → R\ns : Finset ι\ni : ι\nhi : i ∈ s\nh2i : g i + h i ≤ f i\nhgf : ∀ j ∈ s, j ≠ i → g j ≤ f j\nhhf : ∀ j ∈ s, j ≠ i → h j ≤ f j\ni✝ : ι\na✝¹ : i✝ ∈ s\na✝ : ¬i✝ = i\n⊢ i✝ ≠ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n ","nextTactic":"assumption","declUpToTactic":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.706_0.RJ9z80YJpu1cs9E","decl":"/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : Fintype ι\ninst✝ : OrderedCancelCommMonoid M\nf : ι → M\nhf : 1 < f\n⊢ ∃ i ∈ Finset.univ, 1 < 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x ��� p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n assumption\n#align finset.prod_add_prod_le' Finset.prod_add_prod_le'\n\nend CanonicallyOrderedCommSemiring\n\nend Finset\n\nnamespace Fintype\nsection OrderedCommMonoid\nvariable [Fintype ι] [OrderedCommMonoid M] {f : ι → M}\n\n@[to_additive (attr := mono) sum_mono]\ntheorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦\n Finset.prod_le_prod' fun x _ ↦ hfg x\n#align fintype.prod_mono' Fintype.prod_mono'\n#align fintype.sum_mono Fintype.sum_mono\n\n@[to_additive sum_nonneg]\nlemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' λ _ _ ↦ hf _\n\n@[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' λ _ _ ↦ hf _\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\nvariable [Fintype ι] [OrderedCancelCommMonoid M] {f : ι → M}\n\n@[to_additive sum_strictMono]\ntheorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x :=\n fun _ _ hfg ↦\n let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg\n Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩\n#align fintype.prod_strict_mono' Fintype.prod_strictMono'\n#align fintype.sum_strict_mono Fintype.sum_strictMono\n\n@[to_additive sum_pos]\nlemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=\n Finset.one_lt_prod' (λ _ _ ↦ hf.le _) $ by ","nextTactic":"simpa using (Pi.lt_def.1 hf).2","declUpToTactic":"@[to_additive sum_pos]\nlemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=\n Finset.one_lt_prod' (λ _ _ ↦ hf.le _) $ by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.754_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_pos]\nlemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : Fintype ι\ninst✝ : OrderedCancelCommMonoid M\nf : ι → M\nhf : f < 1\n⊢ ∃ i ∈ Finset.univ, f i < 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ��� ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : �� a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n assumption\n#align finset.prod_add_prod_le' Finset.prod_add_prod_le'\n\nend CanonicallyOrderedCommSemiring\n\nend Finset\n\nnamespace Fintype\nsection OrderedCommMonoid\nvariable [Fintype ι] [OrderedCommMonoid M] {f : ι → M}\n\n@[to_additive (attr := mono) sum_mono]\ntheorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦\n Finset.prod_le_prod' fun x _ ↦ hfg x\n#align fintype.prod_mono' Fintype.prod_mono'\n#align fintype.sum_mono Fintype.sum_mono\n\n@[to_additive sum_nonneg]\nlemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' λ _ _ ↦ hf _\n\n@[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' λ _ _ ↦ hf _\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\nvariable [Fintype ι] [OrderedCancelCommMonoid M] {f : ι → M}\n\n@[to_additive sum_strictMono]\ntheorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x :=\n fun _ _ hfg ↦\n let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg\n Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩\n#align fintype.prod_strict_mono' Fintype.prod_strictMono'\n#align fintype.sum_strict_mono Fintype.sum_strictMono\n\n@[to_additive sum_pos]\nlemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=\n Finset.one_lt_prod' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive]\nlemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 :=\n Finset.prod_lt_one' (λ _ _ ↦ hf.le _) $ by ","nextTactic":"simpa using (Pi.lt_def.1 hf).2","declUpToTactic":"@[to_additive]\nlemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 :=\n Finset.prod_lt_one' (λ _ _ ↦ hf.le _) $ by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.758_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\nlemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : Fintype ι\ninst✝ : OrderedCancelCommMonoid M\nf : ι → M\nhf : 1 ≤ f\n⊢ 1 < ∏ i : ι, f i ↔ 1 < f","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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n assumption\n#align finset.prod_add_prod_le' Finset.prod_add_prod_le'\n\nend CanonicallyOrderedCommSemiring\n\nend Finset\n\nnamespace Fintype\nsection OrderedCommMonoid\nvariable [Fintype ι] [OrderedCommMonoid M] {f : ι → M}\n\n@[to_additive (attr := mono) sum_mono]\ntheorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦\n Finset.prod_le_prod' fun x _ ↦ hfg x\n#align fintype.prod_mono' Fintype.prod_mono'\n#align fintype.sum_mono Fintype.sum_mono\n\n@[to_additive sum_nonneg]\nlemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' λ _ _ ↦ hf _\n\n@[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' λ _ _ ↦ hf _\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\nvariable [Fintype ι] [OrderedCancelCommMonoid M] {f : ι → M}\n\n@[to_additive sum_strictMono]\ntheorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x :=\n fun _ _ hfg ↦\n let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg\n Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩\n#align fintype.prod_strict_mono' Fintype.prod_strictMono'\n#align fintype.sum_strict_mono Fintype.sum_strictMono\n\n@[to_additive sum_pos]\nlemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=\n Finset.one_lt_prod' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive]\nlemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 :=\n Finset.prod_lt_one' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by\n ","nextTactic":"obtain rfl | hf := hf.eq_or_lt","declUpToTactic":"@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.762_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f "} +{"state":"case inl\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : Fintype ι\ninst✝ : OrderedCancelCommMonoid M\nhf : 1 ≤ 1\n⊢ 1 < ∏ i : ι, OfNat.ofNat 1 i ↔ 1 < 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n assumption\n#align finset.prod_add_prod_le' Finset.prod_add_prod_le'\n\nend CanonicallyOrderedCommSemiring\n\nend Finset\n\nnamespace Fintype\nsection OrderedCommMonoid\nvariable [Fintype ι] [OrderedCommMonoid M] {f : ι → M}\n\n@[to_additive (attr := mono) sum_mono]\ntheorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦\n Finset.prod_le_prod' fun x _ ↦ hfg x\n#align fintype.prod_mono' Fintype.prod_mono'\n#align fintype.sum_mono Fintype.sum_mono\n\n@[to_additive sum_nonneg]\nlemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' λ _ _ ↦ hf _\n\n@[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' λ _ _ ↦ hf _\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\nvariable [Fintype ι] [OrderedCancelCommMonoid M] {f : ι → M}\n\n@[to_additive sum_strictMono]\ntheorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x :=\n fun _ _ hfg ↦\n let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg\n Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩\n#align fintype.prod_strict_mono' Fintype.prod_strictMono'\n#align fintype.sum_strict_mono Fintype.sum_strictMono\n\n@[to_additive sum_pos]\nlemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=\n Finset.one_lt_prod' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive]\nlemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 :=\n Finset.prod_lt_one' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by\n obtain rfl | hf := hf.eq_or_lt <;> ","nextTactic":"simp [*, one_lt_prod]","declUpToTactic":"@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by\n obtain rfl | hf := hf.eq_or_lt <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.762_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f "} +{"state":"case inr\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : Fintype ι\ninst✝ : OrderedCancelCommMonoid M\nf : ι → M\nhf✝ : 1 ≤ f\nhf : 1 < f\n⊢ 1 < ∏ i : ι, f i ↔ 1 < f","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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n assumption\n#align finset.prod_add_prod_le' Finset.prod_add_prod_le'\n\nend CanonicallyOrderedCommSemiring\n\nend Finset\n\nnamespace Fintype\nsection OrderedCommMonoid\nvariable [Fintype ι] [OrderedCommMonoid M] {f : ι → M}\n\n@[to_additive (attr := mono) sum_mono]\ntheorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦\n Finset.prod_le_prod' fun x _ ↦ hfg x\n#align fintype.prod_mono' Fintype.prod_mono'\n#align fintype.sum_mono Fintype.sum_mono\n\n@[to_additive sum_nonneg]\nlemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' λ _ _ ↦ hf _\n\n@[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' λ _ _ ↦ hf _\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\nvariable [Fintype ι] [OrderedCancelCommMonoid M] {f : ι → M}\n\n@[to_additive sum_strictMono]\ntheorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x :=\n fun _ _ hfg ↦\n let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg\n Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩\n#align fintype.prod_strict_mono' Fintype.prod_strictMono'\n#align fintype.sum_strict_mono Fintype.sum_strictMono\n\n@[to_additive sum_pos]\nlemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=\n Finset.one_lt_prod' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive]\nlemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 :=\n Finset.prod_lt_one' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by\n obtain rfl | hf := hf.eq_or_lt <;> ","nextTactic":"simp [*, one_lt_prod]","declUpToTactic":"@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by\n obtain rfl | hf := hf.eq_or_lt <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.762_0.RJ9z80YJpu1cs9E","decl":"@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : Fintype ι\ninst✝ : OrderedCancelCommMonoid M\nf : ι → M\nhf : f ≤ 1\n⊢ ∏ i : ι, f i < 1 ↔ f < 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n assumption\n#align finset.prod_add_prod_le' Finset.prod_add_prod_le'\n\nend CanonicallyOrderedCommSemiring\n\nend Finset\n\nnamespace Fintype\nsection OrderedCommMonoid\nvariable [Fintype ι] [OrderedCommMonoid M] {f : ι → M}\n\n@[to_additive (attr := mono) sum_mono]\ntheorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦\n Finset.prod_le_prod' fun x _ ↦ hfg x\n#align fintype.prod_mono' Fintype.prod_mono'\n#align fintype.sum_mono Fintype.sum_mono\n\n@[to_additive sum_nonneg]\nlemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' λ _ _ ↦ hf _\n\n@[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' λ _ _ ↦ hf _\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\nvariable [Fintype ι] [OrderedCancelCommMonoid M] {f : ι → M}\n\n@[to_additive sum_strictMono]\ntheorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x :=\n fun _ _ hfg ↦\n let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg\n Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩\n#align fintype.prod_strict_mono' Fintype.prod_strictMono'\n#align fintype.sum_strict_mono Fintype.sum_strictMono\n\n@[to_additive sum_pos]\nlemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=\n Finset.one_lt_prod' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive]\nlemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 :=\n Finset.prod_lt_one' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by\n obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod]\n\n@[to_additive]\nlemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 := by\n ","nextTactic":"obtain rfl | hf := hf.eq_or_lt","declUpToTactic":"@[to_additive]\nlemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.766_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\nlemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 "} +{"state":"case inl\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : Fintype ι\ninst✝ : OrderedCancelCommMonoid M\nhf : 1 ≤ 1\n⊢ ∏ i : ι, OfNat.ofNat 1 i < 1 ↔ 1 < 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n assumption\n#align finset.prod_add_prod_le' Finset.prod_add_prod_le'\n\nend CanonicallyOrderedCommSemiring\n\nend Finset\n\nnamespace Fintype\nsection OrderedCommMonoid\nvariable [Fintype ι] [OrderedCommMonoid M] {f : ι → M}\n\n@[to_additive (attr := mono) sum_mono]\ntheorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦\n Finset.prod_le_prod' fun x _ ↦ hfg x\n#align fintype.prod_mono' Fintype.prod_mono'\n#align fintype.sum_mono Fintype.sum_mono\n\n@[to_additive sum_nonneg]\nlemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' λ _ _ ↦ hf _\n\n@[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' λ _ _ ↦ hf _\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\nvariable [Fintype ι] [OrderedCancelCommMonoid M] {f : ι → M}\n\n@[to_additive sum_strictMono]\ntheorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x :=\n fun _ _ hfg ↦\n let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg\n Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩\n#align fintype.prod_strict_mono' Fintype.prod_strictMono'\n#align fintype.sum_strict_mono Fintype.sum_strictMono\n\n@[to_additive sum_pos]\nlemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=\n Finset.one_lt_prod' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive]\nlemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 :=\n Finset.prod_lt_one' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by\n obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod]\n\n@[to_additive]\nlemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 := by\n obtain rfl | hf := hf.eq_or_lt <;> ","nextTactic":"simp [*, prod_lt_one]","declUpToTactic":"@[to_additive]\nlemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 := by\n obtain rfl | hf := hf.eq_or_lt <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.766_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\nlemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 "} +{"state":"case inr\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : Fintype ι\ninst✝ : OrderedCancelCommMonoid M\nf : ι → M\nhf✝ : f ≤ 1\nhf : f < 1\n⊢ ∏ i : ι, f i < 1 ↔ f < 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n assumption\n#align finset.prod_add_prod_le' Finset.prod_add_prod_le'\n\nend CanonicallyOrderedCommSemiring\n\nend Finset\n\nnamespace Fintype\nsection OrderedCommMonoid\nvariable [Fintype ι] [OrderedCommMonoid M] {f : ι → M}\n\n@[to_additive (attr := mono) sum_mono]\ntheorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦\n Finset.prod_le_prod' fun x _ ↦ hfg x\n#align fintype.prod_mono' Fintype.prod_mono'\n#align fintype.sum_mono Fintype.sum_mono\n\n@[to_additive sum_nonneg]\nlemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' λ _ _ ↦ hf _\n\n@[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' λ _ _ ↦ hf _\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\nvariable [Fintype ι] [OrderedCancelCommMonoid M] {f : ι → M}\n\n@[to_additive sum_strictMono]\ntheorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x :=\n fun _ _ hfg ↦\n let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg\n Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩\n#align fintype.prod_strict_mono' Fintype.prod_strictMono'\n#align fintype.sum_strict_mono Fintype.sum_strictMono\n\n@[to_additive sum_pos]\nlemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=\n Finset.one_lt_prod' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive]\nlemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 :=\n Finset.prod_lt_one' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by\n obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod]\n\n@[to_additive]\nlemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 := by\n obtain rfl | hf := hf.eq_or_lt <;> ","nextTactic":"simp [*, prod_lt_one]","declUpToTactic":"@[to_additive]\nlemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 := by\n obtain rfl | hf := hf.eq_or_lt <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.766_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\nlemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : Fintype ι\ninst✝ : OrderedCancelCommMonoid M\nf : ι → M\nhf : 1 ≤ f\n⊢ ∏ i : ι, f i = 1 ↔ f = 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ��� ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n assumption\n#align finset.prod_add_prod_le' Finset.prod_add_prod_le'\n\nend CanonicallyOrderedCommSemiring\n\nend Finset\n\nnamespace Fintype\nsection OrderedCommMonoid\nvariable [Fintype ι] [OrderedCommMonoid M] {f : ι → M}\n\n@[to_additive (attr := mono) sum_mono]\ntheorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦\n Finset.prod_le_prod' fun x _ ↦ hfg x\n#align fintype.prod_mono' Fintype.prod_mono'\n#align fintype.sum_mono Fintype.sum_mono\n\n@[to_additive sum_nonneg]\nlemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' λ _ _ ↦ hf _\n\n@[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' λ _ _ ↦ hf _\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\nvariable [Fintype ι] [OrderedCancelCommMonoid M] {f : ι → M}\n\n@[to_additive sum_strictMono]\ntheorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x :=\n fun _ _ hfg ↦\n let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg\n Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩\n#align fintype.prod_strict_mono' Fintype.prod_strictMono'\n#align fintype.sum_strict_mono Fintype.sum_strictMono\n\n@[to_additive sum_pos]\nlemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=\n Finset.one_lt_prod' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive]\nlemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 :=\n Finset.prod_lt_one' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by\n obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod]\n\n@[to_additive]\nlemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 := by\n obtain rfl | hf := hf.eq_or_lt <;> simp [*, prod_lt_one]\n\n@[to_additive]\nlemma prod_eq_one_iff_of_one_le (hf : 1 ≤ f) : ∏ i, f i = 1 ↔ f = 1 := by\n ","nextTactic":"simpa only [(one_le_prod hf).not_gt_iff_eq, hf.not_gt_iff_eq]\n using (one_lt_prod_iff_of_one_le hf).not","declUpToTactic":"@[to_additive]\nlemma prod_eq_one_iff_of_one_le (hf : 1 ≤ f) : ∏ i, f i = 1 ↔ f = 1 := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.770_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\nlemma prod_eq_one_iff_of_one_le (hf : 1 ≤ f) : ∏ i, f i = 1 ↔ f = 1 "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : Fintype ι\ninst✝ : OrderedCancelCommMonoid M\nf : ι → M\nhf : f ≤ 1\n⊢ ∏ i : ι, f i = 1 ↔ f = 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ��� f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n assumption\n#align finset.prod_add_prod_le' Finset.prod_add_prod_le'\n\nend CanonicallyOrderedCommSemiring\n\nend Finset\n\nnamespace Fintype\nsection OrderedCommMonoid\nvariable [Fintype ι] [OrderedCommMonoid M] {f : ι → M}\n\n@[to_additive (attr := mono) sum_mono]\ntheorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦\n Finset.prod_le_prod' fun x _ ↦ hfg x\n#align fintype.prod_mono' Fintype.prod_mono'\n#align fintype.sum_mono Fintype.sum_mono\n\n@[to_additive sum_nonneg]\nlemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' λ _ _ ↦ hf _\n\n@[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' λ _ _ ↦ hf _\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\nvariable [Fintype ι] [OrderedCancelCommMonoid M] {f : ι → M}\n\n@[to_additive sum_strictMono]\ntheorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x :=\n fun _ _ hfg ↦\n let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg\n Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩\n#align fintype.prod_strict_mono' Fintype.prod_strictMono'\n#align fintype.sum_strict_mono Fintype.sum_strictMono\n\n@[to_additive sum_pos]\nlemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=\n Finset.one_lt_prod' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive]\nlemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 :=\n Finset.prod_lt_one' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by\n obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod]\n\n@[to_additive]\nlemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 := by\n obtain rfl | hf := hf.eq_or_lt <;> simp [*, prod_lt_one]\n\n@[to_additive]\nlemma prod_eq_one_iff_of_one_le (hf : 1 ≤ f) : ∏ i, f i = 1 ↔ f = 1 := by\n simpa only [(one_le_prod hf).not_gt_iff_eq, hf.not_gt_iff_eq]\n using (one_lt_prod_iff_of_one_le hf).not\n\n@[to_additive]\nlemma prod_eq_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i = 1 ↔ f = 1 := by\n ","nextTactic":"simpa only [(prod_le_one hf).not_gt_iff_eq, hf.not_gt_iff_eq, eq_comm]\n using (prod_lt_one_iff_of_le_one hf).not","declUpToTactic":"@[to_additive]\nlemma prod_eq_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i = 1 ↔ f = 1 := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.775_0.RJ9z80YJpu1cs9E","decl":"@[to_additive]\nlemma prod_eq_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i = 1 ↔ f = 1 "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : AddCommMonoid M\ns : Finset ι\nf : ι → WithTop M\n⊢ ∑ i in s, f i = ⊤ ↔ ∃ i ∈ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ �� j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n assumption\n#align finset.prod_add_prod_le' Finset.prod_add_prod_le'\n\nend CanonicallyOrderedCommSemiring\n\nend Finset\n\nnamespace Fintype\nsection OrderedCommMonoid\nvariable [Fintype ι] [OrderedCommMonoid M] {f : ι → M}\n\n@[to_additive (attr := mono) sum_mono]\ntheorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦\n Finset.prod_le_prod' fun x _ ↦ hfg x\n#align fintype.prod_mono' Fintype.prod_mono'\n#align fintype.sum_mono Fintype.sum_mono\n\n@[to_additive sum_nonneg]\nlemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' λ _ _ ↦ hf _\n\n@[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' λ _ _ ↦ hf _\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\nvariable [Fintype ι] [OrderedCancelCommMonoid M] {f : ι → M}\n\n@[to_additive sum_strictMono]\ntheorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x :=\n fun _ _ hfg ↦\n let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg\n Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩\n#align fintype.prod_strict_mono' Fintype.prod_strictMono'\n#align fintype.sum_strict_mono Fintype.sum_strictMono\n\n@[to_additive sum_pos]\nlemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=\n Finset.one_lt_prod' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive]\nlemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 :=\n Finset.prod_lt_one' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by\n obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod]\n\n@[to_additive]\nlemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 := by\n obtain rfl | hf := hf.eq_or_lt <;> simp [*, prod_lt_one]\n\n@[to_additive]\nlemma prod_eq_one_iff_of_one_le (hf : 1 ≤ f) : ∏ i, f i = 1 ↔ f = 1 := by\n simpa only [(one_le_prod hf).not_gt_iff_eq, hf.not_gt_iff_eq]\n using (one_lt_prod_iff_of_one_le hf).not\n\n@[to_additive]\nlemma prod_eq_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i = 1 ↔ f = 1 := by\n simpa only [(prod_le_one hf).not_gt_iff_eq, hf.not_gt_iff_eq, eq_comm]\n using (prod_lt_one_iff_of_le_one hf).not\n\nend OrderedCancelCommMonoid\nend Fintype\n\nnamespace WithTop\n\nopen Finset\n\n/-- A product of finite numbers is still finite -/\ntheorem prod_lt_top [CommMonoidWithZero R] [NoZeroDivisors R] [Nontrivial R] [DecidableEq R] [LT R]\n {s : Finset ι} {f : ι → WithTop R} (h : ∀ i ∈ s, f i ≠ ⊤) : ∏ i in s, f i < ⊤ :=\n prod_induction f (fun a ↦ a < ⊤) (fun _ _ h₁ h₂ ↦ mul_lt_top' h₁ h₂) (coe_lt_top 1)\n fun a ha ↦ WithTop.lt_top_iff_ne_top.2 (h a ha)\n#align with_top.prod_lt_top WithTop.prod_lt_top\n\n/-- A sum of numbers is infinite iff one of them is infinite -/\ntheorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ι} {f : ι → WithTop M} :\n ∑ i in s, f i = ⊤ ↔ ∃ i ∈ s, f i = ⊤ := by\n ","nextTactic":"induction s using Finset.cons_induction","declUpToTactic":"/-- A sum of numbers is infinite iff one of them is infinite -/\ntheorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ι} {f : ι → WithTop M} :\n ∑ i in s, f i = ⊤ ↔ ∃ i ∈ s, f i = ⊤ := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.794_0.RJ9z80YJpu1cs9E","decl":"/-- A sum of numbers is infinite iff one of them is infinite -/\ntheorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ι} {f : ι → WithTop M} :\n ∑ i in s, f i = ⊤ ↔ ∃ i ∈ s, f i = ⊤ "} +{"state":"case empty\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : AddCommMonoid M\nf : ι → WithTop M\n⊢ ∑ i in ∅, f i = ⊤ ↔ ∃ i ∈ ∅, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i �� s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n assumption\n#align finset.prod_add_prod_le' Finset.prod_add_prod_le'\n\nend CanonicallyOrderedCommSemiring\n\nend Finset\n\nnamespace Fintype\nsection OrderedCommMonoid\nvariable [Fintype ι] [OrderedCommMonoid M] {f : ι → M}\n\n@[to_additive (attr := mono) sum_mono]\ntheorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦\n Finset.prod_le_prod' fun x _ ↦ hfg x\n#align fintype.prod_mono' Fintype.prod_mono'\n#align fintype.sum_mono Fintype.sum_mono\n\n@[to_additive sum_nonneg]\nlemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' λ _ _ ↦ hf _\n\n@[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' λ _ _ ↦ hf _\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\nvariable [Fintype ι] [OrderedCancelCommMonoid M] {f : ι → M}\n\n@[to_additive sum_strictMono]\ntheorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x :=\n fun _ _ hfg ↦\n let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg\n Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩\n#align fintype.prod_strict_mono' Fintype.prod_strictMono'\n#align fintype.sum_strict_mono Fintype.sum_strictMono\n\n@[to_additive sum_pos]\nlemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=\n Finset.one_lt_prod' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive]\nlemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 :=\n Finset.prod_lt_one' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by\n obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod]\n\n@[to_additive]\nlemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 := by\n obtain rfl | hf := hf.eq_or_lt <;> simp [*, prod_lt_one]\n\n@[to_additive]\nlemma prod_eq_one_iff_of_one_le (hf : 1 ≤ f) : ∏ i, f i = 1 ↔ f = 1 := by\n simpa only [(one_le_prod hf).not_gt_iff_eq, hf.not_gt_iff_eq]\n using (one_lt_prod_iff_of_one_le hf).not\n\n@[to_additive]\nlemma prod_eq_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i = 1 ↔ f = 1 := by\n simpa only [(prod_le_one hf).not_gt_iff_eq, hf.not_gt_iff_eq, eq_comm]\n using (prod_lt_one_iff_of_le_one hf).not\n\nend OrderedCancelCommMonoid\nend Fintype\n\nnamespace WithTop\n\nopen Finset\n\n/-- A product of finite numbers is still finite -/\ntheorem prod_lt_top [CommMonoidWithZero R] [NoZeroDivisors R] [Nontrivial R] [DecidableEq R] [LT R]\n {s : Finset ι} {f : ι → WithTop R} (h : ∀ i ∈ s, f i ≠ ⊤) : ∏ i in s, f i < ⊤ :=\n prod_induction f (fun a ↦ a < ⊤) (fun _ _ h₁ h₂ ↦ mul_lt_top' h₁ h₂) (coe_lt_top 1)\n fun a ha ↦ WithTop.lt_top_iff_ne_top.2 (h a ha)\n#align with_top.prod_lt_top WithTop.prod_lt_top\n\n/-- A sum of numbers is infinite iff one of them is infinite -/\ntheorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ι} {f : ι → WithTop M} :\n ∑ i in s, f i = ⊤ ↔ ∃ i ∈ s, f i = ⊤ := by\n induction s using Finset.cons_induction <;> ","nextTactic":"simp [*]","declUpToTactic":"/-- A sum of numbers is infinite iff one of them is infinite -/\ntheorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ι} {f : ι → WithTop M} :\n ∑ i in s, f i = ⊤ ↔ ∃ i ∈ s, f i = ⊤ := by\n induction s using Finset.cons_induction <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.794_0.RJ9z80YJpu1cs9E","decl":"/-- A sum of numbers is infinite iff one of them is infinite -/\ntheorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ι} {f : ι → WithTop M} :\n ∑ i in s, f i = ⊤ ↔ ∃ i ∈ s, f i = ⊤ "} +{"state":"case cons\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝ : AddCommMonoid M\nf : ι → WithTop M\na✝¹ : ι\ns✝ : Finset ι\nh✝ : a✝¹ ∉ s✝\na✝ : ∑ i in s✝, f i = ⊤ ↔ ∃ i ∈ s✝, f i = ⊤\n⊢ ∑ i in cons a✝¹ s✝ h✝, f i = ⊤ ↔ ∃ i ∈ cons a✝¹ s✝ h✝, 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι ��� M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n assumption\n#align finset.prod_add_prod_le' Finset.prod_add_prod_le'\n\nend CanonicallyOrderedCommSemiring\n\nend Finset\n\nnamespace Fintype\nsection OrderedCommMonoid\nvariable [Fintype ι] [OrderedCommMonoid M] {f : ι → M}\n\n@[to_additive (attr := mono) sum_mono]\ntheorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦\n Finset.prod_le_prod' fun x _ ↦ hfg x\n#align fintype.prod_mono' Fintype.prod_mono'\n#align fintype.sum_mono Fintype.sum_mono\n\n@[to_additive sum_nonneg]\nlemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' λ _ _ ↦ hf _\n\n@[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' λ _ _ ↦ hf _\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\nvariable [Fintype ι] [OrderedCancelCommMonoid M] {f : ι → M}\n\n@[to_additive sum_strictMono]\ntheorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x :=\n fun _ _ hfg ↦\n let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg\n Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩\n#align fintype.prod_strict_mono' Fintype.prod_strictMono'\n#align fintype.sum_strict_mono Fintype.sum_strictMono\n\n@[to_additive sum_pos]\nlemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=\n Finset.one_lt_prod' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive]\nlemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 :=\n Finset.prod_lt_one' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by\n obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod]\n\n@[to_additive]\nlemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 := by\n obtain rfl | hf := hf.eq_or_lt <;> simp [*, prod_lt_one]\n\n@[to_additive]\nlemma prod_eq_one_iff_of_one_le (hf : 1 ≤ f) : ∏ i, f i = 1 ↔ f = 1 := by\n simpa only [(one_le_prod hf).not_gt_iff_eq, hf.not_gt_iff_eq]\n using (one_lt_prod_iff_of_one_le hf).not\n\n@[to_additive]\nlemma prod_eq_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i = 1 ↔ f = 1 := by\n simpa only [(prod_le_one hf).not_gt_iff_eq, hf.not_gt_iff_eq, eq_comm]\n using (prod_lt_one_iff_of_le_one hf).not\n\nend OrderedCancelCommMonoid\nend Fintype\n\nnamespace WithTop\n\nopen Finset\n\n/-- A product of finite numbers is still finite -/\ntheorem prod_lt_top [CommMonoidWithZero R] [NoZeroDivisors R] [Nontrivial R] [DecidableEq R] [LT R]\n {s : Finset ι} {f : ι → WithTop R} (h : ∀ i ∈ s, f i ≠ ⊤) : ∏ i in s, f i < ⊤ :=\n prod_induction f (fun a ↦ a < ⊤) (fun _ _ h₁ h₂ ↦ mul_lt_top' h₁ h₂) (coe_lt_top 1)\n fun a ha ↦ WithTop.lt_top_iff_ne_top.2 (h a ha)\n#align with_top.prod_lt_top WithTop.prod_lt_top\n\n/-- A sum of numbers is infinite iff one of them is infinite -/\ntheorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ι} {f : ι → WithTop M} :\n ∑ i in s, f i = ⊤ ↔ ∃ i ∈ s, f i = ⊤ := by\n induction s using Finset.cons_induction <;> ","nextTactic":"simp [*]","declUpToTactic":"/-- A sum of numbers is infinite iff one of them is infinite -/\ntheorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ι} {f : ι → WithTop M} :\n ∑ i in s, f i = ⊤ ↔ ∃ i ∈ s, f i = ⊤ := by\n induction s using Finset.cons_induction <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.794_0.RJ9z80YJpu1cs9E","decl":"/-- A sum of numbers is infinite iff one of them is infinite -/\ntheorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ι} {f : ι → WithTop M} :\n ∑ i in s, f i = ⊤ ↔ ∃ i ∈ s, f i = ⊤ "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nM : Type u_4\nN : Type u_5\nG : Type u_6\nk : Type u_7\nR : Type u_8\ninst✝¹ : AddCommMonoid M\ninst✝ : LT M\ns : Finset ι\nf : ι → WithTop M\n⊢ ∑ i in s, f i < ⊤ ↔ ∀ i ∈ 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.Order.AbsoluteValue\nimport Mathlib.Algebra.Order.Ring.WithTop\nimport Mathlib.Algebra.BigOperators.Basic\nimport Mathlib.Data.Fintype.Card\nimport Mathlib.Tactic.GCongr.Core\n\n#align_import algebra.big_operators.order from \"leanprover-community/mathlib\"@\"65a1391a0106c9204fe45bc73a039f056558cb83\"\n\n/-!\n# Results about big operators with values in an ordered algebraic structure.\n\nMostly monotonicity results for the `∏` and `∑` operations.\n\n-/\n\nopen Function\n\nopen BigOperators\n\nvariable {ι α β M N G k R : Type*}\n\nnamespace Finset\n\nsection OrderedCommMonoid\n\nvariable [CommMonoid M] [OrderedCommMonoid N]\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsubmultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be\na nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∏ x in s, g x) ≤ ∏ x in s, f (g x)`. -/\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ _ _) _\n · simp [hs_nonempty.ne_empty]\n · exact Multiset.forall_mem_map_iff.mpr hs\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_nonempty_of_submultiplicative_on_pred Finset.le_prod_nonempty_of_submultiplicative_on_pred\n#align finset.le_sum_nonempty_of_subadditive_on_pred Finset.le_sum_nonempty_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let\n`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let\n`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)\n {s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)\n (fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial\n#align finset.le_prod_nonempty_of_submultiplicative Finset.le_prod_nonempty_of_submultiplicative\n#align finset.le_sum_nonempty_of_subadditive Finset.le_sum_nonempty_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a\nnonempty finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_nonempty_of_subadditive\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map\nsuch that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,\n`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such\nthat `∀ i ∈ s, p (g i)`. Then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)\n (h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))\n (g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)\n · simp [h_one]\n · exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs\n#align finset.le_prod_of_submultiplicative_on_pred Finset.le_prod_of_submultiplicative_on_pred\n#align finset.le_sum_of_subadditive_on_pred Finset.le_sum_of_subadditive_on_pred\n\n/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map\nsuch that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.\nLet `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then\n`f (∑ x in s, g x) ≤ ∑ x in s, f (g x)`. -/\nadd_decl_doc le_sum_of_subadditive_on_pred\n\n/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i in s, g i) ≤ ∏ i in s, f (g i)`. -/\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)\n (h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :\n f (∏ i in s, g i) ≤ ∏ i in s, f (g i) := by\n refine' le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) _\n rw [Multiset.map_map]\n rfl\n#align finset.le_prod_of_submultiplicative Finset.le_prod_of_submultiplicative\n#align finset.le_sum_of_subadditive Finset.le_sum_of_subadditive\n\n/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,\n`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i in s, g i) ≤ ∑ i in s, f (g i)`. -/\nadd_decl_doc le_sum_of_subadditive\n\nvariable {f g : ι → N} {s t : Finset ι}\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then\n`∏ i in s, f i ≤ ∏ i in s, g i`. -/\n@[to_additive sum_le_sum]\ntheorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=\n Multiset.prod_map_le_prod_map f g h\n#align finset.prod_le_prod' Finset.prod_le_prod'\n#align finset.sum_le_sum Finset.sum_le_sum\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then\n`∑ i in s, f i ≤ ∑ i in s, g i`. -/\nadd_decl_doc sum_le_sum\n\n/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or\nequal to the corresponding factor `g i` of another finite product, then `s.prod f ≤ s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod'`, convenient\nfor the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_le_sum]\ntheorem _root_.GCongr.prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : s.prod f ≤ s.prod g :=\n s.prod_le_prod' h\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than\nor equal to the corresponding summand `g i` of another finite sum, then `s.sum f ≤ s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_le_sum`, convenient\nfor the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_le_sum\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i in s, f i :=\n le_trans (by rw [prod_const_one]) (prod_le_prod' h)\n#align finset.one_le_prod' Finset.one_le_prod'\n#align finset.sum_nonneg Finset.sum_nonneg\n\n@[to_additive Finset.sum_nonneg']\ntheorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i : ι in s, f i :=\n Finset.one_le_prod' fun i _ ↦ h i\n#align finset.one_le_prod'' Finset.one_le_prod''\n#align finset.sum_nonneg' Finset.sum_nonneg'\n\n@[to_additive sum_nonpos]\ntheorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 :=\n (prod_le_prod' h).trans_eq (by rw [prod_const_one])\n#align finset.prod_le_one' Finset.prod_le_one'\n#align finset.sum_nonpos Finset.sum_nonpos\n\n@[to_additive sum_le_sum_of_subset_of_nonneg]\ntheorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :\n ∏ i in s, f i ≤ ∏ i in t, f i := by\n classical calc\n ∏ i in s, f i ≤ (∏ i in t \\ s, f i) * ∏ i in s, f i :=\n le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]\n _ = ∏ i in t \\ s ∪ s, f i := (prod_union sdiff_disjoint).symm\n _ = ∏ i in t, f i := by rw [sdiff_union_of_subset h]\n#align finset.prod_le_prod_of_subset_of_one_le' Finset.prod_le_prod_of_subset_of_one_le'\n#align finset.sum_le_sum_of_subset_of_nonneg Finset.sum_le_sum_of_subset_of_nonneg\n\n@[to_additive sum_mono_set_of_nonneg]\ntheorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x in s, f x :=\n fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x\n#align finset.prod_mono_set_of_one_le' Finset.prod_mono_set_of_one_le'\n#align finset.sum_mono_set_of_nonneg Finset.sum_mono_set_of_nonneg\n\n@[to_additive sum_le_univ_sum_of_nonneg]\ntheorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :\n ∏ x in s, f x ≤ ∏ x, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a\n#align finset.prod_le_univ_prod_of_one_le' Finset.prod_le_univ_prod_of_one_le'\n#align finset.sum_le_univ_sum_of_nonneg Finset.sum_le_univ_sum_of_nonneg\n\n-- Porting Note: TODO -- The two next lemmas give the same lemma in additive version\n@[to_additive sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_one_le' :\n (∀ i ∈ s, 1 ≤ f i) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by\n classical\n refine Finset.induction_on s\n (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_\n intro a s ha ih H\n have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem\n rw [prod_insert ha, mul_eq_one_iff' (H _ <| mem_insert_self _ _) (one_le_prod' this),\n forall_mem_insert, ih this]\n#align finset.prod_eq_one_iff_of_one_le' Finset.prod_eq_one_iff_of_one_le'\n#align finset.sum_eq_zero_iff_of_nonneg Finset.sum_eq_zero_iff_of_nonneg\n\n@[to_additive existing sum_eq_zero_iff_of_nonneg]\ntheorem prod_eq_one_iff_of_le_one' :\n (∀ i ∈ s, f i ≤ 1) → ((∏ i in s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=\n @prod_eq_one_iff_of_one_le' _ Nᵒᵈ _ _ _\n#align finset.prod_eq_one_iff_of_le_one' Finset.prod_eq_one_iff_of_le_one'\n-- Porting note: there is no align for the additive version since it aligns to the\n-- same one as the previous lemma\n\n@[to_additive single_le_sum]\ntheorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=\n calc\n f a = ∏ i in {a}, f i := (prod_singleton _ _).symm\n _ ≤ ∏ i in s, f i :=\n prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi\n#align finset.single_le_prod' Finset.single_le_prod'\n#align finset.single_le_sum Finset.single_le_sum\n\n@[to_additive]\nlemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :\n f i * f j ≤ ∏ k in s, f k :=\n calc\n f i * f j = ∏ k in .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]\n _ ≤ ∏ k in s, f k := by\n refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk\n simp [cons_subset, *]\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :\n s.prod f ≤ n ^ s.card := by\n refine' (Multiset.prod_le_pow_card (s.val.map f) n _).trans _\n · simpa using h\n · simp\n#align finset.prod_le_pow_card Finset.prod_le_pow_card\n#align finset.sum_le_card_nsmul Finset.sum_le_card_nsmul\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :\n n ^ s.card ≤ s.prod f := @Finset.prod_le_pow_card _ Nᵒᵈ _ _ _ _ h\n#align finset.pow_card_le_prod Finset.pow_card_le_prod\n#align finset.card_nsmul_le_sum Finset.card_nsmul_le_sum\n\ntheorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)\n (h : ∀ a ∈ s, (f a).card ≤ n) : (s.biUnion f).card ≤ s.card * n :=\n card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h\n#align finset.card_bUnion_le_card_mul Finset.card_biUnion_le_card_mul\n\nvariable {ι' : Type*} [DecidableEq ι']\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]\ntheorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, (1 : N) ≤ ∏ x in s.filter fun x ↦ g x = y, f x) :\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤ ∏ x in s, f x :=\n calc\n (∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x) ≤\n ∏ y in t ∪ s.image g, ∏ x in s.filter fun x ↦ g x = y, f x :=\n prod_le_prod_of_subset_of_one_le' (subset_union_left _ _) fun y _ ↦ h y\n _ = ∏ x in s, f x :=\n prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _\n#align finset.prod_fiberwise_le_prod_of_one_le_prod_fiber' Finset.prod_fiberwise_le_prod_of_one_le_prod_fiber'\n#align finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg Finset.sum_fiberwise_le_sum_of_sum_fiber_nonneg\n\n-- Porting note: Mathport warning: expanding binder collection (y «expr ∉ » t)\n@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]\ntheorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}\n (h : ∀ y ∉ t, ∏ x in s.filter fun x ↦ g x = y, f x ≤ 1) :\n ∏ x in s, f x ≤ ∏ y in t, ∏ x in s.filter fun x ↦ g x = y, f x :=\n @prod_fiberwise_le_prod_of_one_le_prod_fiber' _ Nᵒᵈ _ _ _ _ _ _ _ h\n#align finset.prod_le_prod_fiberwise_of_prod_fiber_le_one' Finset.prod_le_prod_fiberwise_of_prod_fiber_le_one'\n#align finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos Finset.sum_le_sum_fiberwise_of_sum_fiber_nonpos\n\nend OrderedCommMonoid\n\ntheorem abs_sum_le_sum_abs {G : Type*} [LinearOrderedAddCommGroup G] (f : ι → G) (s : Finset ι) :\n |∑ i in s, f i| ≤ ∑ i in s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f\n#align finset.abs_sum_le_sum_abs Finset.abs_sum_le_sum_abs\n\ntheorem abs_sum_of_nonneg {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg hf)]\n#align finset.abs_sum_of_nonneg Finset.abs_sum_of_nonneg\n\ntheorem abs_sum_of_nonneg' {G : Type*} [LinearOrderedAddCommGroup G] {f : ι → G} {s : Finset ι}\n (hf : ∀ i, 0 ≤ f i) : |∑ i : ι in s, f i| = ∑ i : ι in s, f i := by\n rw [abs_of_nonneg (Finset.sum_nonneg' hf)]\n#align finset.abs_sum_of_nonneg' Finset.abs_sum_of_nonneg'\n\ntheorem abs_prod {R : Type*} [LinearOrderedCommRing R] {f : ι → R} {s : Finset ι} :\n |∏ x in s, f x| = ∏ x in s, |f x| :=\n map_prod absHom _ _\n#align finset.abs_prod Finset.abs_prod\n\nsection Pigeonhole\n\nvariable [DecidableEq β]\n\ntheorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, (s.filter fun x ↦ f x = a).card ≤ n) :\n s.card ≤ n * t.card :=\n calc\n s.card = ∑ a in t, (s.filter fun x ↦ f x = a).card := card_eq_sum_card_fiberwise Hf\n _ ≤ ∑ _a in t, n := sum_le_sum hn\n _ = _ := by simp [mul_comm]\n#align finset.card_le_mul_card_image_of_maps_to Finset.card_le_mul_card_image_of_maps_to\n\ntheorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, (s.filter fun x ↦ f x = a).card ≤ n) : s.card ≤ n * (s.image f).card :=\n card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.card_le_mul_card_image Finset.card_le_mul_card_image\n\ntheorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}\n (Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ a ∈ t, n ≤ (s.filter fun x ↦ f x = a).card) :\n n * t.card ≤ s.card :=\n calc\n n * t.card = ∑ _a in t, n := by simp [mul_comm]\n _ ≤ ∑ a in t, (s.filter fun x ↦ f x = a).card := sum_le_sum hn\n _ = s.card := by rw [← card_eq_sum_card_fiberwise Hf]\n#align finset.mul_card_image_le_card_of_maps_to Finset.mul_card_image_le_card_of_maps_to\n\ntheorem mul_card_image_le_card {f : α → β} (s : Finset α) (n : ℕ)\n (hn : ∀ a ∈ s.image f, n ≤ (s.filter fun x ↦ f x = a).card) : n * (s.image f).card ≤ s.card :=\n mul_card_image_le_card_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn\n#align finset.mul_card_image_le_card Finset.mul_card_image_le_card\n\nend Pigeonhole\n\nsection DoubleCounting\n\nvariable [DecidableEq α] {s : Finset α} {B : Finset (Finset α)} {n : ℕ}\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_inter_le (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card ≤ n) :\n (∑ t in B, (s ∩ t).card) ≤ s.card * n := by\n refine' le_trans _ (s.sum_le_card_nsmul _ _ h)\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.sum_card_inter_le Finset.sum_card_inter_le\n\n/-- If every element belongs to at most `n` Finsets, then the sum of their sizes is at most `n`\ntimes how many they are. -/\ntheorem sum_card_le [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card ≤ n) :\n ∑ s in B, s.card ≤ Fintype.card α * n :=\n calc\n ∑ s in B, s.card = ∑ s in B, (univ ∩ s).card := by simp_rw [univ_inter]\n _ ≤ Fintype.card α * n := sum_card_inter_le fun a _ ↦ h a\n#align finset.sum_card_le Finset.sum_card_le\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card_inter (h : ∀ a ∈ s, n ≤ (B.filter (a ∈ ·)).card) :\n s.card * n ≤ ∑ t in B, (s ∩ t).card := by\n apply (s.card_nsmul_le_sum _ _ h).trans\n simp_rw [← filter_mem_eq_inter, card_eq_sum_ones, sum_filter]\n exact sum_comm.le\n#align finset.le_sum_card_inter Finset.le_sum_card_inter\n\n/-- If every element belongs to at least `n` Finsets, then the sum of their sizes is at least `n`\ntimes how many they are. -/\ntheorem le_sum_card [Fintype α] (h : ∀ a, n ≤ (B.filter (a ∈ ·)).card) :\n Fintype.card α * n ≤ ∑ s in B, s.card :=\n calc\n Fintype.card α * n ≤ ∑ s in B, (univ ∩ s).card := le_sum_card_inter fun a _ ↦ h a\n _ = ∑ s in B, s.card := by simp_rw [univ_inter]\n#align finset.le_sum_card Finset.le_sum_card\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card_inter (h : ∀ a ∈ s, (B.filter (a ∈ ·)).card = n) :\n (∑ t in B, (s ∩ t).card) = s.card * n :=\n (sum_card_inter_le fun a ha ↦ (h a ha).le).antisymm (le_sum_card_inter fun a ha ↦ (h a ha).ge)\n#align finset.sum_card_inter Finset.sum_card_inter\n\n/-- If every element belongs to exactly `n` Finsets, then the sum of their sizes is `n` times how\nmany they are. -/\ntheorem sum_card [Fintype α] (h : ∀ a, (B.filter (a ∈ ·)).card = n) :\n ∑ s in B, s.card = Fintype.card α * n := by\n simp_rw [Fintype.card, ← sum_card_inter fun a _ ↦ h a, univ_inter]\n#align finset.sum_card Finset.sum_card\n\ntheorem card_le_card_biUnion {s : Finset ι} {f : ι → Finset α} (hs : (s : Set ι).PairwiseDisjoint f)\n (hf : ∀ i ∈ s, (f i).Nonempty) : s.card ≤ (s.biUnion f).card := by\n rw [card_biUnion hs]\n rw [card_eq_sum_ones]\n exact sum_le_sum fun i hi ↦ (hf i hi).card_pos\n#align finset.card_le_card_bUnion Finset.card_le_card_biUnion\n\ntheorem card_le_card_biUnion_add_card_fiber {s : Finset ι} {f : ι → Finset α}\n (hs : (s : Set ι).PairwiseDisjoint f) :\n s.card ≤ (s.biUnion f).card + (s.filter fun i ↦ f i = ∅).card := by\n rw [← Finset.filter_card_add_filter_neg_card_eq_card fun i ↦ f i = ∅]\n rw [add_comm]\n exact\n add_le_add_right\n ((card_le_card_biUnion (hs.subset <| filter_subset _ _) fun i hi ↦\n nonempty_of_ne_empty <| (mem_filter.1 hi).2).trans <|\n card_le_of_subset <| biUnion_subset_biUnion_of_subset_left _ <| filter_subset _ _)\n _\n#align finset.card_le_card_bUnion_add_card_fiber Finset.card_le_card_biUnion_add_card_fiber\n\ntheorem card_le_card_biUnion_add_one {s : Finset ι} {f : ι → Finset α} (hf : Injective f)\n (hs : (s : Set ι).PairwiseDisjoint f) : s.card ≤ (s.biUnion f).card + 1 :=\n (card_le_card_biUnion_add_card_fiber hs).trans <|\n add_le_add_left\n (card_le_one.2 fun _ hi _ hj ↦ hf <| (mem_filter.1 hi).2.trans (mem_filter.1 hj).2.symm) _\n#align finset.card_le_card_bUnion_add_one Finset.card_le_card_biUnion_add_one\n\nend DoubleCounting\n\nsection CanonicallyOrderedCommMonoid\n\nvariable [CanonicallyOrderedCommMonoid M] {f : ι → M} {s t : Finset ι}\n\n@[to_additive (attr := simp) sum_eq_zero_iff]\ntheorem prod_eq_one_iff' : ∏ x in s, f x = 1 ↔ ∀ x ∈ s, f x = 1 :=\n prod_eq_one_iff_of_one_le' fun x _ ↦ one_le (f x)\n#align finset.prod_eq_one_iff' Finset.prod_eq_one_iff'\n#align finset.sum_eq_zero_iff Finset.sum_eq_zero_iff\n\n@[to_additive sum_le_sum_of_subset]\ntheorem prod_le_prod_of_subset' (h : s ⊆ t) : ∏ x in s, f x ≤ ∏ x in t, f x :=\n prod_le_prod_of_subset_of_one_le' h fun _ _ _ ↦ one_le _\n#align finset.prod_le_prod_of_subset' Finset.prod_le_prod_of_subset'\n#align finset.sum_le_sum_of_subset Finset.sum_le_sum_of_subset\n\n@[to_additive sum_mono_set]\ntheorem prod_mono_set' (f : ι → M) : Monotone fun s ↦ ∏ x in s, f x := fun _ _ hs ↦\n prod_le_prod_of_subset' hs\n#align finset.prod_mono_set' Finset.prod_mono_set'\n#align finset.sum_mono_set Finset.sum_mono_set\n\n@[to_additive sum_le_sum_of_ne_zero]\ntheorem prod_le_prod_of_ne_one' (h : ∀ x ∈ s, f x ≠ 1 → x ∈ t) :\n ∏ x in s, f x ≤ ∏ x in t, f x := by\n classical calc\n ∏ x in s, f x = (∏ x in s.filter fun x ↦ f x = 1, f x) *\n ∏ x in s.filter fun x ↦ f x ≠ 1, f x := by\n rw [← prod_union]\n rw [filter_union_filter_neg_eq]\n exact disjoint_filter.2 fun _ _ h n_h ↦ n_h h\n _ ≤ ∏ x in t, f x :=\n mul_le_of_le_one_of_le\n (prod_le_one' <| by simp only [mem_filter, and_imp]; exact fun _ _ ↦ le_of_eq)\n (prod_le_prod_of_subset' <| by simpa only [subset_iff, mem_filter, and_imp] )\n#align finset.prod_le_prod_of_ne_one' Finset.prod_le_prod_of_ne_one'\n#align finset.sum_le_sum_of_ne_zero Finset.sum_le_sum_of_ne_zero\n\nend CanonicallyOrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod' hle hlt\n#align finset.prod_lt_prod' Finset.prod_lt_prod'\n#align finset.sum_lt_sum Finset.sum_lt_sum\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s.Nonempty) (hlt : ∀ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i :=\n Multiset.prod_lt_prod_of_nonempty' (by aesop) hlt\n#align finset.prod_lt_prod_of_nonempty' Finset.prod_lt_prod_of_nonempty'\n#align finset.sum_lt_sum_of_nonempty Finset.sum_lt_sum_of_nonempty\n\n/-- In an ordered commutative monoid, if each factor `f i` of one nontrivial finite product is\nstrictly less than the corresponding factor `g i` of another nontrivial finite product, then\n`s.prod f < s.prod g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_lt_prod_of_nonempty'`,\nconvenient for the `gcongr` tactic. -/\n@[to_additive (attr := gcongr) GCongr.sum_lt_sum_of_nonempty]\ntheorem _root_.GCongr.prod_lt_prod_of_nonempty' (hs : s.Nonempty) (Hlt : ∀ i ∈ s, f i < g i) :\n s.prod f < s.prod g :=\n s.prod_lt_prod_of_nonempty' hs Hlt\n\n/-- In an ordered additive commutative monoid, if each summand `f i` of one nontrivial finite sum is\nstrictly less than the corresponding summand `g i` of another nontrivial finite sum, then\n`s.sum f < s.sum g`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.sum_lt_sum_of_nonempty`,\nconvenient for the `gcongr` tactic. -/\nadd_decl_doc GCongr.sum_lt_sum_of_nonempty\n\n-- Porting note: TODO -- calc indentation\n@[to_additive sum_lt_sum_of_subset]\ntheorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i ∉ s) (hlt : 1 < f i)\n (hle : ∀ j ∈ t, j ∉ s → 1 ≤ f j) : ∏ j in s, f j < ∏ j in t, f j := by\n classical calc\n ∏ j in s, f j < ∏ j in insert i s, f j := by\n rw [prod_insert hs]\n exact lt_mul_of_one_lt_left' (∏ j in s, f j) hlt\n _ ≤ ∏ j in t, f j := by\n apply prod_le_prod_of_subset_of_one_le'\n · simp [Finset.insert_subset_iff, h, ht]\n · intro x hx h'x\n simp only [mem_insert, not_or] at h'x\n exact hle x hx h'x.2\n#align finset.prod_lt_prod_of_subset' Finset.prod_lt_prod_of_subset'\n#align finset.sum_lt_sum_of_subset Finset.sum_lt_sum_of_subset\n\n@[to_additive single_lt_sum]\ntheorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)\n (hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=\n calc\n f i = ∏ k in {i}, f k := by rw [prod_singleton]\n _ < ∏ k in s, f k :=\n prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt\n fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)\n#align finset.single_lt_prod' Finset.single_lt_prod'\n#align finset.single_lt_sum Finset.single_lt_sum\n\n@[to_additive sum_pos]\ntheorem one_lt_prod (h : ∀ i ∈ s, 1 < f i) (hs : s.Nonempty) : 1 < ∏ i in s, f i :=\n lt_of_le_of_lt (by rw [prod_const_one]) <| prod_lt_prod_of_nonempty' hs h\n#align finset.one_lt_prod Finset.one_lt_prod\n#align finset.sum_pos Finset.sum_pos\n\n@[to_additive]\ntheorem prod_lt_one (h : ∀ i ∈ s, f i < 1) (hs : s.Nonempty) : ∏ i in s, f i < 1 :=\n (prod_lt_prod_of_nonempty' hs h).trans_le (by rw [prod_const_one])\n#align finset.prod_lt_one Finset.prod_lt_one\n#align finset.sum_neg Finset.sum_neg\n\n@[to_additive sum_pos']\ntheorem one_lt_prod' (h : ∀ i ∈ s, 1 ≤ f i) (hs : ∃ i ∈ s, 1 < f i) : 1 < ∏ i in s, f i :=\n prod_const_one.symm.trans_lt <| prod_lt_prod' h hs\n#align finset.one_lt_prod' Finset.one_lt_prod'\n#align finset.sum_pos' Finset.sum_pos'\n\n@[to_additive]\ntheorem prod_lt_one' (h : ∀ i ∈ s, f i ≤ 1) (hs : ∃ i ∈ s, f i < 1) : ∏ i in s, f i < 1 :=\n prod_const_one.le.trans_lt' <| prod_lt_prod' h hs\n#align finset.prod_lt_one' Finset.prod_lt_one'\n#align finset.sum_neg' Finset.sum_neg'\n\n@[to_additive]\ntheorem prod_eq_prod_iff_of_le {f g : ι → M} (h : ∀ i ∈ s, f i ≤ g i) :\n ((∏ i in s, f i) = ∏ i in s, g i) ↔ ∀ i ∈ s, f i = g i := by\n classical\n revert h\n refine Finset.induction_on s (fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h),\n fun _ ↦ rfl⟩) fun a s ha ih H ↦ ?_\n specialize ih fun i ↦ H i ∘ Finset.mem_insert_of_mem\n rw [Finset.prod_insert ha]\n rw [Finset.prod_insert ha]\n rw [Finset.forall_mem_insert]\n rw [← ih]\n exact\n mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a))\n (Finset.prod_le_prod' fun i ↦ H i ∘ Finset.mem_insert_of_mem)\n#align finset.prod_eq_prod_iff_of_le Finset.prod_eq_prod_iff_of_le\n#align finset.sum_eq_sum_iff_of_le Finset.sum_eq_sum_iff_of_le\n\nvariable [DecidableEq ι]\n\n@[to_additive] lemma prod_sdiff_le_prod_sdiff :\n ∏ i in s \\ t, f i ≤ ∏ i in t \\ s, f i ↔ ∏ i in s, f i ≤ ∏ i in t, f i := by\n rw [← mul_le_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\n@[to_additive] lemma prod_sdiff_lt_prod_sdiff :\n ∏ i in s \\ t, f i < ∏ i in t \\ s, f i ↔ ∏ i in s, f i < ∏ i in t, f i := by\n rw [← mul_lt_mul_iff_right, ← prod_union (disjoint_sdiff_inter _ _), sdiff_union_inter,\n ← prod_union, inter_comm, sdiff_union_inter];\n simpa only [inter_comm] using disjoint_sdiff_inter t s\n\nend OrderedCancelCommMonoid\n\nsection LinearOrderedCancelCommMonoid\n\nvariable [LinearOrderedCancelCommMonoid M] {f g : ι → M} {s t : Finset ι}\n\n@[to_additive exists_lt_of_sum_lt]\ntheorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) : ∃ i ∈ s, f i < g i := by\n contrapose! Hlt with Hle\n exact prod_le_prod' Hle\n#align finset.exists_lt_of_prod_lt' Finset.exists_lt_of_prod_lt'\n#align finset.exists_lt_of_sum_lt Finset.exists_lt_of_sum_lt\n\n@[to_additive exists_le_of_sum_le]\ntheorem exists_le_of_prod_le' (hs : s.Nonempty) (Hle : ∏ i in s, f i ≤ ∏ i in s, g i) :\n ∃ i ∈ s, f i ≤ g i := by\n contrapose! Hle with Hlt\n exact prod_lt_prod_of_nonempty' hs Hlt\n#align finset.exists_le_of_prod_le' Finset.exists_le_of_prod_le'\n#align finset.exists_le_of_sum_le Finset.exists_le_of_sum_le\n\n@[to_additive exists_pos_of_sum_zero_of_exists_nonzero]\ntheorem exists_one_lt_of_prod_one_of_exists_ne_one' (f : ι → M) (h₁ : ∏ i in s, f i = 1)\n (h₂ : ∃ i ∈ s, f i ≠ 1) : ∃ i ∈ s, 1 < f i := by\n contrapose! h₁\n obtain ⟨i, m, i_ne⟩ : ∃ i ∈ s, f i ≠ 1 := h₂\n apply ne_of_lt\n calc\n ∏ j in s, f j < ∏ j in s, 1 := prod_lt_prod' h₁ ⟨i, m, (h₁ i m).lt_of_ne i_ne⟩\n _ = 1 := prod_const_one\n#align finset.exists_one_lt_of_prod_one_of_exists_ne_one' Finset.exists_one_lt_of_prod_one_of_exists_ne_one'\n#align finset.exists_pos_of_sum_zero_of_exists_nonzero Finset.exists_pos_of_sum_zero_of_exists_nonzero\n\nend LinearOrderedCancelCommMonoid\n\nsection OrderedCommSemiring\n\nvariable [OrderedCommSemiring R] {f g : ι → R} {s t : Finset ι}\n\nopen Classical\n\n-- this is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=\n prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0\n#align finset.prod_nonneg Finset.prod_nonneg\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for\nthe case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n ∏ i in s, f i ≤ ∏ i in s, g i := by\n induction' s using Finset.induction with a s has ih h\n · simp\n · simp only [prod_insert has]\n apply mul_le_mul\n · exact h1 a (mem_insert_self a s)\n · refine ih (fun x H ↦ h0 _ ?_) (fun x H ↦ h1 _ ?_) <;> exact mem_insert_of_mem H\n · apply prod_nonneg fun x H ↦ h0 x (mem_insert_of_mem H)\n · apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s))\n#align finset.prod_le_prod Finset.prod_le_prod\n\n/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the\nproduct of `f i` is less than or equal to the product of `g i`.\n\nThis is a variant (beta-reduced) version of the standard lemma `Finset.prod_le_prod`, convenient\nfor the `gcongr` tactic. -/\n@[gcongr]\ntheorem _root_.GCongr.prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :\n s.prod f ≤ s.prod g :=\n s.prod_le_prod h0 h1\n\n/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.\nSee also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/\ntheorem prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i in s, f i ≤ 1 := by\n convert ← prod_le_prod h0 h1\n exact Finset.prod_const_one\n#align finset.prod_le_one Finset.prod_le_one\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/\ntheorem prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)\n (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)\n (hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)\n · rw [right_distrib]\n refine add_le_add ?_ ?_ <;>\n · refine mul_le_mul_of_nonneg_left ?_ ?_\n · refine prod_le_prod ?_ ?_\n <;> simp (config := { contextual := true }) [*]\n · try apply_assumption\n try assumption\n · apply prod_nonneg\n simp only [and_imp, mem_sdiff, mem_singleton]\n intro j h1j h2j\n exact le_trans (hg j h1j) (hgf j h1j h2j)\n#align finset.prod_add_prod_le Finset.prod_add_prod_le\n\nend OrderedCommSemiring\n\nsection StrictOrderedCommSemiring\n\nvariable [StrictOrderedCommSemiring R] {f g : ι → R} {s : Finset ι}\n\n-- This is also true for an ordered commutative multiplicative monoid with zero\ntheorem prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i in s, f i :=\n prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0\n#align finset.prod_pos Finset.prod_pos\n\ntheorem prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)\n (hlt : ∃ i ∈ s, f i < g i) :\n ∏ i in s, f i < ∏ i in s, g i := by\n classical\n obtain ⟨i, hi, hilt⟩ := hlt\n rw [← insert_erase hi]\n rw [prod_insert (not_mem_erase _ _)]\n rw [prod_insert (not_mem_erase _ _)]\n apply mul_lt_mul hilt\n · exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))\n (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)\n · exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)\n · exact le_of_lt <| (hf i hi).trans hilt\n\ntheorem prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)\n (h_ne : s.Nonempty) :\n ∏ i in s, f i < ∏ i in s, g i := by\n apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)\n obtain ⟨i, hi⟩ := h_ne\n exact ⟨i, hi, hfg i hi⟩\n\nend StrictOrderedCommSemiring\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring R] {f g h : ι → R} {s : Finset ι} {i : ι}\n\n/-- Note that the name is to match `CanonicallyOrderedCommSemiring.mul_pos`. -/\n@[simp] lemma _root_.CanonicallyOrderedCommSemiring.prod_pos [Nontrivial R] :\n 0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=\n CanonicallyOrderedCommSemiring.multiset_prod_pos.trans Multiset.forall_mem_map_iff\n#align canonically_ordered_comm_semiring.prod_pos CanonicallyOrderedCommSemiring.prod_pos\n\n/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the\n sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedCommSemiring`.\n-/\ntheorem prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)\n (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i in s, g i) + ∏ i in s, h i) ≤ ∏ i in s, f i := by\n classical\n simp_rw [prod_eq_mul_prod_diff_singleton hi]\n refine' le_trans _ (mul_le_mul_right' h2i _)\n rw [right_distrib]\n apply add_le_add <;> apply mul_le_mul_left' <;> apply prod_le_prod' <;>\n simp only [and_imp, mem_sdiff, mem_singleton] <;>\n intros <;>\n apply_assumption <;>\n assumption\n#align finset.prod_add_prod_le' Finset.prod_add_prod_le'\n\nend CanonicallyOrderedCommSemiring\n\nend Finset\n\nnamespace Fintype\nsection OrderedCommMonoid\nvariable [Fintype ι] [OrderedCommMonoid M] {f : ι → M}\n\n@[to_additive (attr := mono) sum_mono]\ntheorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦\n Finset.prod_le_prod' fun x _ ↦ hfg x\n#align fintype.prod_mono' Fintype.prod_mono'\n#align fintype.sum_mono Fintype.sum_mono\n\n@[to_additive sum_nonneg]\nlemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' λ _ _ ↦ hf _\n\n@[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' λ _ _ ↦ hf _\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\nvariable [Fintype ι] [OrderedCancelCommMonoid M] {f : ι → M}\n\n@[to_additive sum_strictMono]\ntheorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x :=\n fun _ _ hfg ↦\n let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg\n Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩\n#align fintype.prod_strict_mono' Fintype.prod_strictMono'\n#align fintype.sum_strict_mono Fintype.sum_strictMono\n\n@[to_additive sum_pos]\nlemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=\n Finset.one_lt_prod' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive]\nlemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 :=\n Finset.prod_lt_one' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2\n\n@[to_additive sum_pos_iff_of_nonneg]\nlemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by\n obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod]\n\n@[to_additive]\nlemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 := by\n obtain rfl | hf := hf.eq_or_lt <;> simp [*, prod_lt_one]\n\n@[to_additive]\nlemma prod_eq_one_iff_of_one_le (hf : 1 ≤ f) : ∏ i, f i = 1 ↔ f = 1 := by\n simpa only [(one_le_prod hf).not_gt_iff_eq, hf.not_gt_iff_eq]\n using (one_lt_prod_iff_of_one_le hf).not\n\n@[to_additive]\nlemma prod_eq_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i = 1 ↔ f = 1 := by\n simpa only [(prod_le_one hf).not_gt_iff_eq, hf.not_gt_iff_eq, eq_comm]\n using (prod_lt_one_iff_of_le_one hf).not\n\nend OrderedCancelCommMonoid\nend Fintype\n\nnamespace WithTop\n\nopen Finset\n\n/-- A product of finite numbers is still finite -/\ntheorem prod_lt_top [CommMonoidWithZero R] [NoZeroDivisors R] [Nontrivial R] [DecidableEq R] [LT R]\n {s : Finset ι} {f : ι → WithTop R} (h : ∀ i ∈ s, f i ≠ ⊤) : ∏ i in s, f i < ⊤ :=\n prod_induction f (fun a ↦ a < ⊤) (fun _ _ h₁ h₂ ↦ mul_lt_top' h₁ h₂) (coe_lt_top 1)\n fun a ha ↦ WithTop.lt_top_iff_ne_top.2 (h a ha)\n#align with_top.prod_lt_top WithTop.prod_lt_top\n\n/-- A sum of numbers is infinite iff one of them is infinite -/\ntheorem sum_eq_top_iff [AddCommMonoid M] {s : Finset ι} {f : ι → WithTop M} :\n ∑ i in s, f i = ⊤ ↔ ∃ i ∈ s, f i = ⊤ := by\n induction s using Finset.cons_induction <;> simp [*]\n#align with_top.sum_eq_top_iff WithTop.sum_eq_top_iff\n\n/-- A sum of finite numbers is still finite -/\ntheorem sum_lt_top_iff [AddCommMonoid M] [LT M] {s : Finset ι} {f : ι → WithTop M} :\n ∑ i in s, f i < ⊤ ↔ ∀ i ∈ s, f i < ⊤ := by\n ","nextTactic":"simp only [WithTop.lt_top_iff_ne_top, ne_eq, sum_eq_top_iff, not_exists, not_and]","declUpToTactic":"/-- A sum of finite numbers is still finite -/\ntheorem sum_lt_top_iff [AddCommMonoid M] [LT M] {s : Finset ι} {f : ι → WithTop M} :\n ∑ i in s, f i < ⊤ ↔ ∀ i ∈ s, f i < ⊤ := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Order.800_0.RJ9z80YJpu1cs9E","decl":"/-- A sum of finite numbers is still finite -/\ntheorem sum_lt_top_iff [AddCommMonoid M] [LT M] {s : Finset ι} {f : ι → WithTop M} :\n ∑ i in s, f i < ⊤ ↔ ∀ i ∈ s, f i < ⊤ "}